using glorp and active record

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

using glorp and active record

Sean Glazier
Hi,

I have been trying to get glorp using active record working in pharo 5. 

I have a descriptor class for it and the classes inherit from active Record.

I describe the table as:
tableForAnswer: aTable
| vistorId questionId |
(aTable createFieldNamed: 'id' type: platform serial) bePrimaryKey.
questionId := aTable createFieldNamed: 'questionId' type: platform integer.
vistorId := aTable createFieldNamed: 'vistorId' type: platform integer.
aTable createFieldNamed: 'answer' type: platform text.
aTable
addForeignKeyFrom: vistorId
to: ((self tableNamed: 'VISITORS') fieldNamed: 'ID')
suffixExpression:
'MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE'.
aTable
addForeignKeyFrom: questionId
to: ((self tableNamed: 'QUESTIONS') fieldNamed: 'ID')
suffixExpression:
'MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE'


the table in the DB was preexisting.

when I do Answer findAll 

I get and error that it is expecting a number for the id field.

in the PostgresSQLPlaform serial is defined thusly.
serial
"For postgresql, we use sequences, and explicitly get the values ourselves, so just tell the database that they're integers."

^self typeNamed: #serial ifAbsentPut: [GlorpSerialType new typeString: 'integer'].

What the DB hands back is 'nextval('answers_id_seq'::regclass)' which seems correct if it is telling me that there exists a sequence for this field and that is the correct command to issue for the field.

am I defining this table incorrectly? or should I bag using active Record. I kind of liked it when working in Visualworks because there were also tools that would read in and describe the tables and then tools to assit when you needed to migrate to another version and do the changes etc.

FYI this is the query that is being run that fails.
SELECT t1.table_name, t1.table_schema, t1.column_name, t1.is_nullable, t1.data_type, t1.column_default, t1.character_maximum_length,  EXISTS (SELECT DISTINCT 'x'
 FROM ((INFORMATION_SCHEMA.table_constraints s1t1 INNER JOIN INFORMATION_SCHEMA.key_column_usage s1t3 ON ((s1t1.table_name = s1t3.table_name) AND ((s1t1.table_schema = s1t3.table_schema) AND (s1t1.constraint_name = s1t3.constraint_name)))) INNER JOIN INFORMATION_SCHEMA.columns s1t2 ON (((s1t3.column_name = s1t2.column_name) AND (s1t3.table_schema = s1t2.table_schema)) AND (s1t3.table_name = s1t2.table_name)))
 WHERE ((s1t1.constraint_type = 'PRIMARY KEY') AND ((s1t2.column_name = t1.column_name) AND (((s1t2.table_schema = t1.table_schema) AND (s1t2.table_name = t1.table_name)) AND ((s1t2.table_schema = t1.table_schema) AND (s1t2.table_name = t1.table_name))))))
 FROM INFORMATION_SCHEMA.columns t1
 WHERE ((t1.table_name = 'answers') AND (t1.table_schema = 'public'))



it looks as though it is reading in the schema and is expecting and integer because we told it to in the serial method on the PostgesSQLPlatform.

As much as I love diving into these frameworks to figure out the deep inner workings, I really need to be getting data in and out without a fuss.

Should I follow the DBX example where the descriptor is orthogonal to the model and one does not subclass from active record?

I also note that not all the glorp tests pass. I think the were rather minor fails like timezone issues or something. It took a while but the test created a number of tables in the DB. 

So again Have I done something Obtuse that I qught to be slapped for here?

thanks
Reply | Threaded
Open this post in threaded view
|

Re: using glorp and active record

Esteban A. Maringolo
How did you create the tables? There is a sequence for the ID in the database?
Also, I don't understand why you call it "ActiveRecord".

If you can share some code, DDL of the table, I'll be able to help you better.

Regards,

Esteban A. Maringolo

ps: I'm cross replying to the Glorp mailing list.

2016-08-08 11:02 GMT-03:00 Sean Glazier <[hidden email]>:

> Hi,
>
> I have been trying to get glorp using active record working in pharo 5.
>
> I have a descriptor class for it and the classes inherit from active Record.
>
> I describe the table as:
> tableForAnswer: aTable
> | vistorId questionId |
> (aTable createFieldNamed: 'id' type: platform serial) bePrimaryKey.
> questionId := aTable createFieldNamed: 'questionId' type: platform integer.
> vistorId := aTable createFieldNamed: 'vistorId' type: platform integer.
> aTable createFieldNamed: 'answer' type: platform text.
> aTable
> addForeignKeyFrom: vistorId
> to: ((self tableNamed: 'VISITORS') fieldNamed: 'ID')
> suffixExpression:
> 'MATCH SIMPLE
>       ON UPDATE NO ACTION ON DELETE CASCADE'.
> aTable
> addForeignKeyFrom: questionId
> to: ((self tableNamed: 'QUESTIONS') fieldNamed: 'ID')
> suffixExpression:
> 'MATCH SIMPLE
>       ON UPDATE NO ACTION ON DELETE CASCADE'
>
>
> the table in the DB was preexisting.
>
> when I do Answer findAll
>
> I get and error that it is expecting a number for the id field.
>
> in the PostgresSQLPlaform serial is defined thusly.
> serial
> "For postgresql, we use sequences, and explicitly get the values ourselves,
> so just tell the database that they're integers."
>
> ^self typeNamed: #serial ifAbsentPut: [GlorpSerialType new typeString:
> 'integer'].
>
> What the DB hands back is 'nextval('answers_id_seq'::regclass)' which seems
> correct if it is telling me that there exists a sequence for this field and
> that is the correct command to issue for the field.
>
> am I defining this table incorrectly? or should I bag using active Record. I
> kind of liked it when working in Visualworks because there were also tools
> that would read in and describe the tables and then tools to assit when you
> needed to migrate to another version and do the changes etc.
>
> FYI this is the query that is being run that fails.
> SELECT t1.table_name, t1.table_schema, t1.column_name, t1.is_nullable,
> t1.data_type, t1.column_default, t1.character_maximum_length,  EXISTS
> (SELECT DISTINCT 'x'
>  FROM ((INFORMATION_SCHEMA.table_constraints s1t1 INNER JOIN
> INFORMATION_SCHEMA.key_column_usage s1t3 ON ((s1t1.table_name =
> s1t3.table_name) AND ((s1t1.table_schema = s1t3.table_schema) AND
> (s1t1.constraint_name = s1t3.constraint_name)))) INNER JOIN
> INFORMATION_SCHEMA.columns s1t2 ON (((s1t3.column_name = s1t2.column_name)
> AND (s1t3.table_schema = s1t2.table_schema)) AND (s1t3.table_name =
> s1t2.table_name)))
>  WHERE ((s1t1.constraint_type = 'PRIMARY KEY') AND ((s1t2.column_name =
> t1.column_name) AND (((s1t2.table_schema = t1.table_schema) AND
> (s1t2.table_name = t1.table_name)) AND ((s1t2.table_schema =
> t1.table_schema) AND (s1t2.table_name = t1.table_name))))))
>  FROM INFORMATION_SCHEMA.columns t1
>  WHERE ((t1.table_name = 'answers') AND (t1.table_schema = 'public'))
>
>
>
> it looks as though it is reading in the schema and is expecting and integer
> because we told it to in the serial method on the PostgesSQLPlatform.
>
> As much as I love diving into these frameworks to figure out the deep inner
> workings, I really need to be getting data in and out without a fuss.
>
> Should I follow the DBX example where the descriptor is orthogonal to the
> model and one does not subclass from active record?
>
> I also note that not all the glorp tests pass. I think the were rather minor
> fails like timezone issues or something. It took a while but the test
> created a number of tables in the DB.
>
> So again Have I done something Obtuse that I qught to be slapped for here?
>
> thanks

Reply | Threaded
Open this post in threaded view
|

Re: using glorp and active record

stepharo
Hi esteban

Niall will probably contact you because he is releasing a new version of
Glorp.

Stef


Le 8/8/16 à 17:01, Esteban A. Maringolo a écrit :

> How did you create the tables? There is a sequence for the ID in the database?
> Also, I don't understand why you call it "ActiveRecord".
>
> If you can share some code, DDL of the table, I'll be able to help you better.
>
> Regards,
>
> Esteban A. Maringolo
>
> ps: I'm cross replying to the Glorp mailing list.
>
> 2016-08-08 11:02 GMT-03:00 Sean Glazier <[hidden email]>:
>> Hi,
>>
>> I have been trying to get glorp using active record working in pharo 5.
>>
>> I have a descriptor class for it and the classes inherit from active Record.
>>
>> I describe the table as:
>> tableForAnswer: aTable
>> | vistorId questionId |
>> (aTable createFieldNamed: 'id' type: platform serial) bePrimaryKey.
>> questionId := aTable createFieldNamed: 'questionId' type: platform integer.
>> vistorId := aTable createFieldNamed: 'vistorId' type: platform integer.
>> aTable createFieldNamed: 'answer' type: platform text.
>> aTable
>> addForeignKeyFrom: vistorId
>> to: ((self tableNamed: 'VISITORS') fieldNamed: 'ID')
>> suffixExpression:
>> 'MATCH SIMPLE
>>        ON UPDATE NO ACTION ON DELETE CASCADE'.
>> aTable
>> addForeignKeyFrom: questionId
>> to: ((self tableNamed: 'QUESTIONS') fieldNamed: 'ID')
>> suffixExpression:
>> 'MATCH SIMPLE
>>        ON UPDATE NO ACTION ON DELETE CASCADE'
>>
>>
>> the table in the DB was preexisting.
>>
>> when I do Answer findAll
>>
>> I get and error that it is expecting a number for the id field.
>>
>> in the PostgresSQLPlaform serial is defined thusly.
>> serial
>> "For postgresql, we use sequences, and explicitly get the values ourselves,
>> so just tell the database that they're integers."
>>
>> ^self typeNamed: #serial ifAbsentPut: [GlorpSerialType new typeString:
>> 'integer'].
>>
>> What the DB hands back is 'nextval('answers_id_seq'::regclass)' which seems
>> correct if it is telling me that there exists a sequence for this field and
>> that is the correct command to issue for the field.
>>
>> am I defining this table incorrectly? or should I bag using active Record. I
>> kind of liked it when working in Visualworks because there were also tools
>> that would read in and describe the tables and then tools to assit when you
>> needed to migrate to another version and do the changes etc.
>>
>> FYI this is the query that is being run that fails.
>> SELECT t1.table_name, t1.table_schema, t1.column_name, t1.is_nullable,
>> t1.data_type, t1.column_default, t1.character_maximum_length,  EXISTS
>> (SELECT DISTINCT 'x'
>>   FROM ((INFORMATION_SCHEMA.table_constraints s1t1 INNER JOIN
>> INFORMATION_SCHEMA.key_column_usage s1t3 ON ((s1t1.table_name =
>> s1t3.table_name) AND ((s1t1.table_schema = s1t3.table_schema) AND
>> (s1t1.constraint_name = s1t3.constraint_name)))) INNER JOIN
>> INFORMATION_SCHEMA.columns s1t2 ON (((s1t3.column_name = s1t2.column_name)
>> AND (s1t3.table_schema = s1t2.table_schema)) AND (s1t3.table_name =
>> s1t2.table_name)))
>>   WHERE ((s1t1.constraint_type = 'PRIMARY KEY') AND ((s1t2.column_name =
>> t1.column_name) AND (((s1t2.table_schema = t1.table_schema) AND
>> (s1t2.table_name = t1.table_name)) AND ((s1t2.table_schema =
>> t1.table_schema) AND (s1t2.table_name = t1.table_name))))))
>>   FROM INFORMATION_SCHEMA.columns t1
>>   WHERE ((t1.table_name = 'answers') AND (t1.table_schema = 'public'))
>>
>>
>>
>> it looks as though it is reading in the schema and is expecting and integer
>> because we told it to in the serial method on the PostgesSQLPlatform.
>>
>> As much as I love diving into these frameworks to figure out the deep inner
>> workings, I really need to be getting data in and out without a fuss.
>>
>> Should I follow the DBX example where the descriptor is orthogonal to the
>> model and one does not subclass from active record?
>>
>> I also note that not all the glorp tests pass. I think the were rather minor
>> fails like timezone issues or something. It took a while but the test
>> created a number of tables in the DB.
>>
>> So again Have I done something Obtuse that I qught to be slapped for here?
>>
>> thanks
>


Reply | Threaded
Open this post in threaded view
|

Re: using glorp and active record

Brad Selfridge
Could I be added to any invite list. I have been working on some tools surrounding making GLORP easier to setup and use.

Thanks,
Brad Selfridge
Reply | Threaded
Open this post in threaded view
|

Re: using glorp and active record

Esteban A. Maringolo
There is the Glorp Mailing List / Google Group at [hidden email]

Activity there is rare, but people still read it.

Regards!

Esteban A. Maringolo

2016-09-27 10:21 GMT-03:00 Brad Selfridge <[hidden email]>:
Could I be added to any invite list. I have been working on some tools
surrounding making GLORP easier to setup and use.

Thanks,



-----
Brad Selfridge
--
View this message in context: http://forum.world.st/using-glorp-and-active-record-tp4909996p4917215.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: using glorp and active record

Sean Glazier
In reply to this post by Esteban A. Maringolo
Hi,

Sorry for the delay been really busy. there is aclass called ActiveRecord wher you can subclass model objects from and follow the instructions, glorp will build the database descriptions and mappings. The sequence numbers were defined in  the database. I was using an existing model to map and improve upon. Things went well until glorp was describing the tables in particular the ids that have sequence numbers attached to the id columns.  when writing to save a new object you do not set the id directly but use the auto sequence. the ddl of the tables are as follows:
-- Table: answers

-- DROP TABLE answers;

CREATE TABLE answers
(
  id serial NOT NULL,
  questionid integer,
  visitorid integer,
  answer text,
  optionid integer, -- options for licence scans can havedirect answers for them so we nee to add pointers and backpointer to them in this table as well
  CONSTRAINT answers_pkey PRIMARY KEY (id),
  CONSTRAINT answers_optionid_fkey FOREIGN KEY (optionid)
      REFERENCES options (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT answers_visitorid_fkey FOREIGN KEY (visitorid)
      REFERENCES visitors (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL
)
WITH (
  OIDS=FALSE
);
ALTER TABLE answers
  OWNER TO sean;
COMMENT ON COLUMN answers.optionid IS 'options for licence scans can havedirect answers for them so we nee to add pointers and backpointer to them in this table as well';


-- Index: answers_questionid_idx

-- DROP INDEX answers_questionid_idx;

CREATE INDEX answers_questionid_idx
  ON answers
  USING btree
  (questionid);

-- Index: answers_visitorid_idx

-- DROP INDEX answers_visitorid_idx;

CREATE INDEX answers_visitorid_idx
  ON answers
  USING btree
  (visitorid);


-- Table: moderators

-- DROP TABLE moderators;

CREATE TABLE moderators
(
  id character(36) NOT NULL,
  settingsid character(24),
  name text,
  location text,
  password text,
  hiddenfilter text,
  login text,
  CONSTRAINT moderators_pkey PRIMARY KEY (id),
  CONSTRAINT moderators_settingsid_fkey FOREIGN KEY (settingsid)
      REFERENCES settings (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE
)
WITH (
  OIDS=FALSE
);
ALTER TABLE moderators
  OWNER TO sean;

-- Index: moderators_settingsid_idx

-- DROP INDEX moderators_settingsid_idx;

CREATE INDEX moderators_settingsid_idx
  ON moderators
  USING btree
  (settingsid COLLATE pg_catalog."default");


-- Table: modsessions

-- DROP TABLE modsessions;

CREATE TABLE modsessions
(
  id serial NOT NULL,
  moderatorid character(36),
  starttime timestamp without time zone,
  endtime timestamp without time zone,
  CONSTRAINT modsessions_pkey PRIMARY KEY (id),
  CONSTRAINT modsessions_moderatorid_fkey FOREIGN KEY (moderatorid)
      REFERENCES moderators (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE
)
WITH (
  OIDS=FALSE
);
ALTER TABLE modsessions
  OWNER TO sean;

-- Index: modsessions_moderatorid_idx

-- DROP INDEX modsessions_moderatorid_idx;

CREATE INDEX modsessions_moderatorid_idx
  ON modsessions
  USING btree
  (moderatorid COLLATE pg_catalog."default");


-- Table: options

-- DROP TABLE options;

CREATE TABLE options
(
  id serial NOT NULL,
  questionid integer,
  option text,
  message text,
  islicensequestion boolean, -- tels me if this option is part of a license question group
  answertype text, -- this defines if the option has an answer with logic or with out logic. in the future there might be more answer types with other comple logic. so this field is a string instead of a boolean or an integer. It makes it easier to identify thing by looking at the results
  logicquestionid integer,
  showinstatus boolean,
  showinregistration boolean,
  showinmoderatorscreen boolean,
  CONSTRAINT options_pkey PRIMARY KEY (id),
  CONSTRAINT logicquestion_fk FOREIGN KEY (logicquestionid)
      REFERENCES questions (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE,
  CONSTRAINT options_questionid_fkey FOREIGN KEY (questionid)
      REFERENCES questions (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE
)
WITH (
  OIDS=FALSE
);
ALTER TABLE options
  OWNER TO sean;
COMMENT ON COLUMN options.islicensequestion IS 'tels me if this option is part of a license question group';
COMMENT ON COLUMN options.answertype IS 'this defines if the option has an answer with logic or with out logic. in the future there might be more answer types with other comple logic. so this field is a string instead of a boolean or an integer. It makes it easier to identify thing by looking at the results';


-- Index: options_questionid_idx

-- DROP INDEX options_questionid_idx;

CREATE INDEX options_questionid_idx
  ON options
  USING btree
  (questionid);

-- Table: questions

-- DROP TABLE questions;

CREATE TABLE questions
(
  id serial NOT NULL,
  settingsid character(24),
  question text,
  showinstatus boolean,
  orderno integer,
  qtype integer,
  showinregistration boolean,
  islicensescan boolean, -- is this question part of the licenseScan
  isenabledforlicensescan boolean,
  parentquestionid integer,
  islogicquestion boolean, -- is this a condition logic question
  showinmoderatorscreen boolean, -- a newfield for the new q line
  CONSTRAINT questions_pkey PRIMARY KEY (id),
  CONSTRAINT parentquestion_fk FOREIGN KEY (parentquestionid)
      REFERENCES questions (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE,
  CONSTRAINT questions_settingsid_fkey FOREIGN KEY (settingsid)
      REFERENCES settings (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL
)
WITH (
  OIDS=FALSE
);
ALTER TABLE questions
  OWNER TO sean;
COMMENT ON COLUMN questions.islicensescan IS 'is this question part of the licenseScan';
COMMENT ON COLUMN questions.islogicquestion IS 'is this a condition logic question';
COMMENT ON COLUMN questions.showinmoderatorscreen IS 'a newfield for the new q line';


-- Index: questions_settingsid_idx

-- DROP INDEX questions_settingsid_idx;

CREATE INDEX questions_settingsid_idx
  ON questions
  USING btree
  (settingsid COLLATE pg_catalog."default");

-- Table: selectedoptions

-- DROP TABLE selectedoptions;

CREATE TABLE selectedoptions
(
  id serial NOT NULL,
  answerid integer,
  optionid integer,
  CONSTRAINT selectedoptions_pkey PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE selectedoptions
  OWNER TO sean;

-- Index: selectedoptions_answerid_idx

-- DROP INDEX selectedoptions_answerid_idx;

CREATE INDEX selectedoptions_answerid_idx
  ON selectedoptions
  USING btree
  (answerid);

-- Index: selectedoptions_optionid_idx

-- DROP INDEX selectedoptions_optionid_idx;

CREATE INDEX selectedoptions_optionid_idx
  ON selectedoptions
  USING btree
  (optionid);

-- Table: settings

-- DROP TABLE settings;

CREATE TABLE settings
(
  id character(24) NOT NULL,
  logourl text,
  templatename text,
  successmessage text,
  doprintout boolean,
  regtitle text,
  themecolor text,
  regbgurl text,
  lunchstart timestamp without time zone,
  lunchend timestamp without time zone,
  statustitle text,
  lunchmessage text,
  endofdaymessage text,
  statusbgurl text,
  modbgurl text,
  regtitlecolor text,
  statustitlecolor text,
  statustextno text,
  statustextlocation text,
  statustextest text,
  nummoderators integer,
  showinstatusest boolean,
  estreset timestamp without time zone,
  manualest integer,
  CONSTRAINT settings_pkey PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE settings
  OWNER TO sean;

-- Table: urlsettings

-- DROP TABLE urlsettings;

CREATE TABLE urlsettings
(
  id serial NOT NULL,
  statusurl text,
  registrationurl text,
  moderatorurl text,
  CONSTRAINT urlsettings_pkey PRIMARY KEY (id)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE urlsettings
  OWNER TO sean;

-- Table: visitors

-- DROP TABLE visitors;

CREATE TABLE visitors
(
  id serial NOT NULL,
  moderatorid character(36),
  settingsid character(24),
  no integer,
  createdat timestamp without time zone,
  calledat timestamp without time zone,
  cancelledat timestamp without time zone,
  showedupat timestamp without time zone,
  processedat timestamp without time zone,
  comments text,
  finishedloginat timestamp without time zone,
  CONSTRAINT visitors_pkey PRIMARY KEY (id),
  CONSTRAINT visitors_settingsid_fkey FOREIGN KEY (settingsid)
      REFERENCES settings (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT vistors_moderatorid_fkey FOREIGN KEY (moderatorid)
      REFERENCES moderators (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
  OIDS=FALSE
);
ALTER TABLE visitors
  OWNER TO sean;

-- Index: visitors_moderatorid_idx

-- DROP INDEX visitors_moderatorid_idx;

CREATE INDEX visitors_moderatorid_idx
  ON visitors
  USING btree
  (moderatorid COLLATE pg_catalog."default");

-- Index: visitors_settingsid_idx

-- DROP INDEX visitors_settingsid_idx;

CREATE INDEX visitors_settingsid_idx
  ON visitors
  USING btree
  (settingsid COLLATE pg_catalog."default");



-- Sequence: answers_id_seq

-- DROP SEQUENCE answers_id_seq;

CREATE SEQUENCE answers_id_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 220
  CACHE 1;
ALTER TABLE answers_id_seq
  OWNER TO sean;


-- Sequence: modsessions_id_seq

-- DROP SEQUENCE modsessions_id_seq;

CREATE SEQUENCE modsessions_id_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 40
  CACHE 1;
ALTER TABLE modsessions_id_seq
  OWNER TO sean;


-- Sequence: options_id_seq

-- DROP SEQUENCE options_id_seq;

CREATE SEQUENCE options_id_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 68
  CACHE 1;
ALTER TABLE options_id_seq
  OWNER TO sean;

-- Sequence: questions_id_seq

-- DROP SEQUENCE questions_id_seq;

CREATE SEQUENCE questions_id_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 18
  CACHE 1;
ALTER TABLE questions_id_seq
  OWNER TO sean;

-- Sequence: selectedoptions_id_seq

-- DROP SEQUENCE selectedoptions_id_seq;

CREATE SEQUENCE selectedoptions_id_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 46
  CACHE 1;
ALTER TABLE selectedoptions_id_seq
  OWNER TO sean;

-- Sequence: urlsettings_id_seq

-- DROP SEQUENCE urlsettings_id_seq;

CREATE SEQUENCE urlsettings_id_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;
ALTER TABLE urlsettings_id_seq
  OWNER TO sean;

-- Sequence: visitors_id_seq

-- DROP SEQUENCE visitors_id_seq;

CREATE SEQUENCE visitors_id_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 52
  CACHE 1;
ALTER TABLE visitors_id_seq
  OWNER TO sean;



 
Kind Regards,
 
Sean Glazier
 

On Mon, Aug 8, 2016 at 11:01 AM, Esteban A. Maringolo <[hidden email]> wrote:
How did you create the tables? There is a sequence for the ID in the database?
Also, I don't understand why you call it "ActiveRecord".

If you can share some code, DDL of the table, I'll be able to help you better.

Regards,

Esteban A. Maringolo

ps: I'm cross replying to the Glorp mailing list.

2016-08-08 11:02 GMT-03:00 Sean Glazier <[hidden email]>:
> Hi,
>
> I have been trying to get glorp using active record working in pharo 5.
>
> I have a descriptor class for it and the classes inherit from active Record.
>
> I describe the table as:
> tableForAnswer: aTable
> | vistorId questionId |
> (aTable createFieldNamed: 'id' type: platform serial) bePrimaryKey.
> questionId := aTable createFieldNamed: 'questionId' type: platform integer.
> vistorId := aTable createFieldNamed: 'vistorId' type: platform integer.
> aTable createFieldNamed: 'answer' type: platform text.
> aTable
> addForeignKeyFrom: vistorId
> to: ((self tableNamed: 'VISITORS') fieldNamed: 'ID')
> suffixExpression:
> 'MATCH SIMPLE
>       ON UPDATE NO ACTION ON DELETE CASCADE'.
> aTable
> addForeignKeyFrom: questionId
> to: ((self tableNamed: 'QUESTIONS') fieldNamed: 'ID')
> suffixExpression:
> 'MATCH SIMPLE
>       ON UPDATE NO ACTION ON DELETE CASCADE'
>
>
> the table in the DB was preexisting.
>
> when I do Answer findAll
>
> I get and error that it is expecting a number for the id field.
>
> in the PostgresSQLPlaform serial is defined thusly.
> serial
> "For postgresql, we use sequences, and explicitly get the values ourselves,
> so just tell the database that they're integers."
>
> ^self typeNamed: #serial ifAbsentPut: [GlorpSerialType new typeString:
> 'integer'].
>
> What the DB hands back is 'nextval('answers_id_seq'::regclass)' which seems
> correct if it is telling me that there exists a sequence for this field and
> that is the correct command to issue for the field.
>
> am I defining this table incorrectly? or should I bag using active Record. I
> kind of liked it when working in Visualworks because there were also tools
> that would read in and describe the tables and then tools to assit when you
> needed to migrate to another version and do the changes etc.
>
> FYI this is the query that is being run that fails.
> SELECT t1.table_name, t1.table_schema, t1.column_name, t1.is_nullable,
> t1.data_type, t1.column_default, t1.character_maximum_length,  EXISTS
> (SELECT DISTINCT 'x'
>  FROM ((INFORMATION_SCHEMA.table_constraints s1t1 INNER JOIN
> INFORMATION_SCHEMA.key_column_usage s1t3 ON ((s1t1.table_name =
> s1t3.table_name) AND ((s1t1.table_schema = s1t3.table_schema) AND
> (s1t1.constraint_name = s1t3.constraint_name)))) INNER JOIN
> INFORMATION_SCHEMA.columns s1t2 ON (((s1t3.column_name = s1t2.column_name)
> AND (s1t3.table_schema = s1t2.table_schema)) AND (s1t3.table_name =
> s1t2.table_name)))
>  WHERE ((s1t1.constraint_type = 'PRIMARY KEY') AND ((s1t2.column_name =
> t1.column_name) AND (((s1t2.table_schema = t1.table_schema) AND
> (s1t2.table_name = t1.table_name)) AND ((s1t2.table_schema =
> t1.table_schema) AND (s1t2.table_name = t1.table_name))))))
>  FROM INFORMATION_SCHEMA.columns t1
>  WHERE ((t1.table_name = 'answers') AND (t1.table_schema = 'public'))
>
>
>
> it looks as though it is reading in the schema and is expecting and integer
> because we told it to in the serial method on the PostgesSQLPlatform.
>
> As much as I love diving into these frameworks to figure out the deep inner
> workings, I really need to be getting data in and out without a fuss.
>
> Should I follow the DBX example where the descriptor is orthogonal to the
> model and one does not subclass from active record?
>
> I also note that not all the glorp tests pass. I think the were rather minor
> fails like timezone issues or something. It took a while but the test
> created a number of tables in the DB.
>
> So again Have I done something Obtuse that I qught to be slapped for here?
>
> thanks