[Dbix-class] many to many insert

Peter Rabbitson rabbit+dbic at rabbit.us
Thu Dec 3 09:08:31 GMT 2009

Jon wrote:
> Hello,
> I am new to DBIx Class and I am trying to insert a record that
> contains a many to many relationship.  I *think* that inserting into
> the record should populate the necessary foreign tables, but I can't
> get that to work.  Do I need to populate them separately?  That seems
> wrong.  This is how I have the relationship setup.
>  ...
> And it fails to create the writers_songs record, even if the writers
> already exist.  I ran a trace to see what is going on, and this is
> what I gathered,
> It tries to select from writers_songs,
> SELECT me.writer, me.song, me.publisher, me.percentage FROM
> writers_songs me WHERE ( ( me.song = ? AND me.writer IS NULL ) )
> but it never attempts to get the writer foreign key.  SO, when it
> tries to insert into writers_songs with a null writer, it fails...
> INSERT INTO writers_songs ( song, writer) VALUES ( ?, ? ): '17', 'NULL'
> So, the problem appears to be that it never attempts to select from
> the writers table, or insert into it in the case where the writer
> doesn't yet exist.  Any ideas?

What version of DBIC. Also show the column definitions for the 3 sources
involved. Also do you have a set_primary_key everywhere? Also provide
what Eden asked for.

More information about the DBIx-Class mailing list