Daniel McBrearty wrote:
CREATE TABLE whatever (
id SERIAL PRIMARY KEY,
whatever_id INTEGER NOT NULL REFERENCES whatever(id),

Is there a way to get the id of the object being created in the
statement doing the creation? I don't even know if the db (postgresql)
can do that ... ?

id SERIAL makes the col base itself on a (probably auto-generated) sequence. you can just ask the sequence for the next integer, and use that in the create.

sequences keep issuing integers, never repeat themselves, and are independent of the cols based upon them (so you can do things like get the next seq id, then abort a transaction and rollback, but the next issued id will still be after that last issued, but aborted, one).

to find the sequence name go to the psql shell and type \d <return> and \d whatever <return> (for table "whatever").

not sure what magic DBIC has to aid the above, but I wouldn't be surprised if something was in there somewhere to help you :)

regards,
oliver.
--
Oliver Gorwits, Network Infrastructure Group,
Oxford University Computing Services

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to