[circumflex-orm] retrieve default values from database after save

26 views
Skip to first unread message

sveri

unread,
Apr 24, 2012, 2:50:50 AM4/24/12
to circumfl...@googlegroups.com
Hi everybody,

i created a table with a timestamp column (created_at) which get's set to the time, a new tuple got inserted. I think that's pretty standard in db-development.

However, when i save a new entity with circumflex-orm and it's save() method, it seems like it only  retrieves the generated id from the database, and not the other fields, that are set automatically, like the created_at for instance.

Is there a way to get this done? Or do i have to use the DEFAULT mechanism from circumflex-orm? If so, I'd be curious why you did decide to do it that way?

Best Regards,
Sven

Boris Okunskiy

unread,
Apr 24, 2012, 3:38:46 AM4/24/12
to circumfl...@googlegroups.com
Greeting Sven,

Strictly pragmatical approach: it is way to easier to initialize the field with application, then reselect the record after INSERT and parse it again from result set. Here's how we do it usually:

val createAt = "created_at".TIMESTAMP.NOT_NULL(new Date)

The DEFAULT clause in column definition is meant to be translated to the corresponding DDL statement. I prefer not to deal with DEFAULT values on the backend, but if this is what your application requires, you may add it to your field's definition:

val createAt = "created_at".TIMESTAMP.NOT_NULL.DEFAULT("now()")

Note, however, that Circumflex doesn't automate the re-reading after DMLs, so you would need to call `refresh()` just after your `save()`.

Hope it helps,

Best regards,
Boris Okunskiy

Message has been deleted

sveri

unread,
Apr 24, 2012, 4:59:31 AM4/24/12
to circumfl...@googlegroups.com
Hi Boris, 

thank you very much for your answer.
I think i got with the default approach application wise.
It seems best to me, cause i dont have to refetch the data from database again, what seems to be a bad approach regarding performance.

Best Regards,
Sven
Reply all
Reply to author
Forward
0 new messages