[Dbix-class] insert

Octavian Rasnita orasnita at gmail.com
Sat Jan 20 12:53:35 GMT 2007


Hi,

Is it possible to insert in a table some records based on another resultset?

For example, I have just inserted a user in the "user" table, and then I 
want to insert the roles for this user in the "role" table.

So first I need to insert the user, then to search the "user" table in order 
to get its ID, then loop and insert each role in the "role" table.

Isn't there an easier method?

I have searched if there is an insert_related or something like this, but I 
couldn't find.

Anyway, if I still need to search the "user" table for getting the ID of the 
latest inserted user, isn't there another way of inserting the roles than 
one by one in a foreach loop?

I want to do something like:

insert into role values(1,2), (1,3), (1,4);

Thank you.

Octavian




More information about the Dbix-class mailing list