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 <sglazier...@gmail.com>:
> 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 via email to