[Dbix-class] foreign keys in fixtures for Test::DBIx::Class

Adam Witney awitney at sgul.ac.uk
Sun Nov 23 14:48:39 GMT 2014


Thanks, I had looked at that approach, but I had missed the is_deferrable part, thanks

Adam

-----Original Message-----
From: Darius Jokilehto [mailto:dariusjokilehto at yahoo.co.uk] 
Sent: 22 November 2014 12:26
To: DBIx::Class user and developer list
Subject: Re: [Dbix-class] foreign keys in fixtures for Test::DBIx::Class

You haven't specified the id columns, you need to do this explicitly, or like you said you won't be able to reference them. In other words:

fixture_sets => {
          'basic' => [
              {
                  Person => [
                      [ 'id', 'first_name', 'last_name', 'company_id' ],
                      [ 1, 'John', 'Smith', 10 ],
                  ]
              },{
                  Company => [
                      ['id', 'name'],
                      [10, 'My Company']
                  ]
              }
          ]

      }

This does mean that you'll have to run setval against your sequences to update them.

Also make sure your your foreign keys are deferrable so they get checked at the end of your transaction, not when the rows are inserted.

HTH,
Darius


On Thursday, 20 November 2014, 15:35, Adam Witney <awitney at sgul.ac.uk> wrote:


>
>
>Hi,
>
>I am trying to write some fixtures for testing with Test::DBIx::Class. I can do this for a simple one table test, but am having trouble doing it when I have a foreign key between two tables. In the file "t/etc/schema.pl" I have
>
>fixture_sets => {
>          'basic' => [
>              {
>                  Person => [
>                      [ 'first_name', 'last_name', ],
>                      [ 'John', 'Smith' ],
>                  ]
>              },{
>                  Company => [
>                      ['name'],
>                      ['My Company']
>                  ]
>              }
>          ]
>      }
>
>But I cannot figure out how to assign the Company to Person John  Smith. Does anyone have a working example of this syntax?
>
>The becomes a problem when using foreign keys in PostgreSQL, as it can't create the Person row without an id for the company row
>
>Thanks for any help
>
>Adam 
>
>_______________________________________________
>List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
>IRC: irc.perl.org#dbix-class
>SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
>Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
>
>

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk



More information about the DBIx-Class mailing list