my
$schema
= DBICTest->init_schema();
plan
tests
=> 9;
my
$artist
=
$schema
->resultset (
'Artist'
)->first;
my
$genre
=
$schema
->resultset (
'Genre'
)
->create ({
name
=>
'par excellence'
});
is (
$genre
->search_related(
'model_cd'
)->count, 0,
'No cds yet'
);
$genre
->update_or_create_related (
'model_cd'
, {
artist
=>
$artist
,
year
=> 2009,
title
=>
'the best thing since sliced bread'
,
});
is (
$genre
->search_related(
'model_cd'
)->count, 1,
'One cd'
);
my
$cd
=
$genre
->find_related (
'model_cd'
, {});
is_deeply (
{
map
{
$_
,
$cd
->get_column (
$_
) }
qw/artist year title/
},
{
artist
=>
$artist
->id,
year
=> 2009,
title
=>
'the best thing since sliced bread'
,
},
'CD created correctly'
,
);
$genre
->update_or_create_related (
'model_cd'
, {
year
=> 2010,
title
=>
'the best thing since sliced bread'
,
});
is (
$genre
->search_related(
'model_cd'
)->count, 1,
'Still one cd'
);
$cd
=
$genre
->find_related (
'model_cd'
, {});
is_deeply (
{
map
{
$_
,
$cd
->get_column (
$_
) }
qw/artist year title/
},
{
artist
=>
$artist
->id,
year
=> 2010,
title
=>
'the best thing since sliced bread'
,
},
'CD year column updated correctly'
,
);
$genre
->update_or_create_related (
'model_cd'
, {
title
=>
'the best thing since vertical toasters'
,
});
is (
$genre
->search_related(
'model_cd'
)->count, 1,
'Still one cd'
);
$cd
=
$genre
->find_related (
'model_cd'
, {});
is_deeply (
{
map
{
$_
,
$cd
->get_column (
$_
) }
qw/artist year title/
},
{
artist
=>
$artist
->id,
year
=> 2010,
title
=>
'the best thing since vertical toasters'
,
},
'CD title column updated correctly'
,
);
$genre
->update_or_create_related (
'model_cd'
, {
year
=> 2011,
});
is (
$genre
->search_related(
'model_cd'
)->count, 1,
'Still one cd'
);
$cd
=
$genre
->find_related (
'model_cd'
, {});
is_deeply (
{
map
{
$_
,
$cd
->get_column (
$_
) }
qw/artist year title/
},
{
artist
=>
$artist
->id,
year
=> 2011,
title
=>
'the best thing since vertical toasters'
,
},
'CD year column updated correctly without a disambiguator'
,
);