Hi,

 

Putting a Repeatable inside a Repeatable does not seems to work when coming to 
the save_to_model part. 

 

Below a test based on HTML-FormFu-0.02004 that fails. It works ok until 
‘save_to_model’ is called and does not save the 2nd ‘has_many’ constraint. I do 
not have read access to the Model::DBIC part in the svn so I pasted the code 
below. I can create a patch to execute if you tell me how to have svn access to 
the current “t/save_to_model/” tests.

 

If this is not the place to post such messages, just let me know.

 

Benoît Galy

 

 

 

t/save_to_model/has_many_repeatable_nested.yml

---

---

auto_fieldset: 1

 

elements:

  - type: Hidden

    name: id

 

  - type: Text

    name: name

 

  - type: Repeatable

    nested_name: addresses

    counter_name: count

 

    elements:

      - type: Hidden

        name: id

 

      - type: Text

        name: address

 

      - type: Repeatable

        nested_name: windows

        counter_name: count_windows

 

        elements:

          - type: Hidden

            name: id

 

          - type: Text

            name: shape

 

  - type: Hidden

    name: count

 

  - type: Submit

    name: submit

t/save_to_model/has_many_repeatable_nested.t

 

use warnings;

use Test::More;

 

BEGIN {

    eval "use DBIx::Class 0.08002";

    if ($@) {

        plan skip_all => 'DBIx::Class required';

        exit;

    }

}

 

plan tests => 8;

 

use HTML::FormFu;

use lib 't/lib';

use DBICTestLib 'new_db';

use MySchema;

 

new_db();

 

my $form = HTML::FormFu->new;

 

$form->load_config_file('t/save_to_model/has_many_repeatable_nested.yml');

 

my $schema = MySchema->connect('dbi:SQLite:dbname=t/test.db');

 

my $user_rs = $schema->resultset('User');

my $address_rs = $schema->resultset('Address');

my $window_rs = $schema->resultset('Window');

 

{

    # insert some entries we'll ignore, so our rels don't have same ids

    # user 1

    my $u1 = $user_rs->new_result({ name => 'foo' });

    $u1->insert;

    # address 1

    my $a1 = $u1->new_related( 'addresses' => { address => 'somewhere' } );

    $a1->insert;

    # window 1

    my $w1 = $a1->new_related( 'windows' => { shape => 'rectangular'});

 

    # should get user id 2

    my $u2 = $user_rs->new_result({

        name => 'nick',

        });

    $u2->insert;

 

    # should get address id 2

    my $a2 = $u2->new_related( 'addresses', { address => 'home' } );

    $a2->insert;

 

    # should get address id 3

    my $a3 = $u2->new_related( 'addresses', { address => 'office' } );

    $a3->insert;

 

    # should get window id 2

    my $w2 = $a2->new_related( 'windows' => { shape => 'circular'});

 

}

 

{

    $form->process({

        'id'    => 2,

        'name'  => 'new nick',

        'count' => 2,

        'addresses.id_1'      => 2,

        'addresses.address_1' => 'new home',

        'addresses.id_2'      => 3,

        'addresses.address_2' => 'new office',

        'addresses.windows.id_1_1' => 2,

        'addresses.windows.shape' => 'modern art',

    });

 

    ok( $form->submitted_and_valid );

 

    my $row = $user_rs->find(2);

 

    $form->save_to_model( $row );

 

    my $user = $user_rs->find(2);

 

    is( $user->name, 'new nick' );

 

    my @add = $user->addresses->all;

 

    is( scalar @add, 2 );

 

    is( $add[0]->id, 2 );

    is( $add[0]->address, 'new home' );

 

    is( $add[1]->id, 3 );

    is( $add[1]->address, 'new office' );

 

    my @windows = $add[0]->windows->all;

 

    is ( scalar @windows, 1);

 

    is ($windows[0]->id, 2);

    is ($windows[0]->shape, 'modern art' );

}

 

Adding to t/lib/DBICTestLib.pm

 

(…)

    $dbh->do( <<SQL );

CREATE TABLE window (

    id        INTEGER PRIMARY KEY,

    address   INTEGER,

    shape     TEXT

);

SQL

(…)

 

t/lib/MySchema/Window.pm

 

 

package MySchema::Window;

use strict;

use warnings;

 

use base 'DBIx::Class';

 

__PACKAGE__->load_components(qw/ Core /);

 

__PACKAGE__->table("window");

 

__PACKAGE__->add_columns(

    id        => { data_type => "INTEGER" },

    address   => { data_type => "INTEGER" },

    shape     => { data_type => "TEXT" },

);

 

__PACKAGE__->set_primary_key("id");

 

__PACKAGE__->belongs_to( address => 'MySchema::Address' );

 

1;

_______________________________________________
HTML-FormFu mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to