DBIx-Class-FormTools

 view release on metacpan or  search on metacpan

t/22.one_to_many_fields.t  view on Meta::CPAN

my $location = $schema->resultset('Location')->new({
    name    => 'Initec',
});


### Create a form with 1 existing objects with one non existing releation
my $formdata = {
    # The existing objects
    $helper->fieldname($film, 'title',      'o1') => 'Sound of music',
    $helper->fieldname($film, 'length',     'o1') => 100,
    $helper->fieldname($film, 'comment',    'o1') => 'The hills are alive...',
    $helper->fieldname($film, 'location_id','o1') => 'o2',
    $helper->fieldname($location, 'name',   'o2') => 'Somewhere over the rainbow',
};
ok(1,"Formdata created:\n".pp($formdata));

my $objects = $helper->formdata_to_object_hash($formdata);
ok(keys %$objects == 2, 'Excacly two object retrieved');
isa_ok($objects->{o1}, 'Schema::Film', 'Object is a Film.');
isa_ok($objects->{o2}, 'Schema::Location', 'Object is a Location.');
isa_ok($objects->{o1}->location, 'Schema::Location', 'Film has a Location.');



( run in 1.766 second using v1.01-cache-2.11-cpan-39bf76dae61 )