[Dbix-class] foreign keys in fixtures for Test::DBIx::Class
Adam Witney
awitney at sgul.ac.uk
Fri Nov 21 09:21:55 GMT 2014
Hi Ben,
Thanks for your email. I was hoping not to have to write too much perl code in the fixtures. Also, can that approach be used in a config file rather than the test file?
Thanks
Adam
> -----Original Message-----
> From: Ben Tilly [mailto:btilly at gmail.com]
> Sent: 20. novembra 2014 19:13
> To: DBIx::Class user and developer list
> Subject: Re: [Dbix-class] foreign keys in fixtures for Test::DBIx::Class
>
> In the documentation there is the following example:
>
> fixtures_ok my $first_album = sub {
> my $schema = shift @_;
> my $cd_rs = $schema->resultset('CD');
> return $cd_rs->create({
> name => 'My First Album',
> track_rs => [
> {position=>1, title=>'the first song'},
> {position=>2, title=>'yet another song'},
> ],
> cd_artist_rs=> [
> {person_artist=>{person => $vanessa}},
> {person_artist=>{person => $john}},
> ],
> });
> }, 'You can even use a code reference for custom fixtures';
>
> This creates a 'CD' object with a list of tracks, and two entries in a join table
> that refer to artists who had been created separately.
>
> You should be able to do the same thing. Create a company, with a result set
> that contains the people who are part of that company.
>
> On Thu, Nov 20, 2014 at 7:06 AM, 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 at lists.scsys.co.uk
More information about the DBIx-Class
mailing list