[Dbix-class] insert

Jess Robinson castaway at desert-island.demon.co.uk
Sat Jan 20 22:16:54 GMT 2007



On Sat, 20 Jan 2007, Octavian Rasnita wrote:

> 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.

Look harder. You want create_related, and yes, when called on the user 
object, it does magically insert the correct user ID for you.

Jess




More information about the Dbix-class mailing list