I have attached the test files and the files I have altered. I have also documented my changes.
The tests create the following relationship Master -> has_many -> Schedule Schedule -> has_many -> Task It then creates a record in Master and two associated records in Schedule.It then creates two records in Task that are both associated with the second record in Schedule.
It then tries to use the form to change the records. It successfully changes the first associated record in Task. (Test 5) It fails to change the second associated record in Task. (Test 7)What can I do to get this fixed? I'm willing to help, but I'm not a strong programmer.
Carl Franks wrote:
Yes - that's a good example. You'll need to checkout the entire distribution with svn co http://html-formfu.googlecode.com/svn/trunk/HTML-FormFu-Model-DBIC The test schema is described in t/lib/MySchema/ If there's no suitable repeatable->repeatable relationships - if you create any new tables, then as well as updating the schema, you'll also need to update new_db() in t/lib/DBICTestLib.pm which is called by each test file to create the sqlite database. Rather than `make test`, I prefer using `prove` to run the test files, as it lets you run an individual test file. You'll need to install Test-Harness to get `prove`. prove -l t/update/has_many_repeatable.t To create a patch file, you'll need to add any new files with `svn add filename` and then create the patch file with `svn diff > patchfile` Good luck! Carl
nested_repeatable_write.t
Description: Troff document
--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Hidden name: sched_count - type: Repeatable nested_name: schedules counter_name: sched_count elements: - type: Hidden name: id - type: Text name: note - type: Hidden name: count - type: Repeatable nested_name: tasks counter_name: count elements: - type: Hidden name: id - type: Text name: detail - type: Submit name: submit
package DBICTestLib; use strict; use warnings; use DBI; use base 'Exporter'; our @EXPORT_OK = qw/ new_db /; END { if ( -f 't/test.db') { unlink 't/test.db'; } } sub output_html { my ($form) = @_; open my $fh, '>', 'out.html' or die $!; print $fh <<HTML; <html> <body> $form </body> </html> HTML } sub new_db { if ( -f 't/test.db' ) { unlink 't/test.db' or die $!; } my $dbh = DBI->connect( 'dbi:SQLite:dbname=t/test.db', { RaiseError => 1, AutoCommit => 1, }); $dbh->do( <<SQL ); CREATE TABLE master ( id INTEGER PRIMARY KEY NOT NULL, text_col TEXT, password_col TEXT, checkbox_col BOOLEAN DEFAULT 1, select_col TEXT, combobox_col TEXT, radio_col TEXT, radiogroup_col TEXT, date_col DATETIME, type_id INTEGER, type2_id INTEGER, not_in_form TEXT ); SQL $dbh->do( <<SQL ); CREATE TABLE note ( id INTEGER PRIMARY KEY NOT NULL, master INTEGER NOT NULL, note TEXT NOT NULL ); SQL $dbh->do( <<SQL ); CREATE TABLE user ( id INTEGER PRIMARY KEY NOT NULL, master INTEGER, name TEXT NOT NULL, title TEXT ); SQL $dbh->do( <<SQL ); CREATE TABLE band ( id INTEGER PRIMARY KEY NOT NULL, manager INTEGER, band TEXT NOT NULL ); SQL $dbh->do( <<SQL ); CREATE TABLE user_band ( user INTEGER NOT NULL, band INTEGER NOT NULL, PRIMARY KEY (user, band) ); SQL $dbh->do( <<SQL ); CREATE TABLE address ( id INTEGER PRIMARY KEY NOT NULL, user INTEGER NOT NULL, my_label TEXT, address TEXT NOT NULL ); SQL $dbh->do( <<SQL ); CREATE TABLE type ( id INTEGER PRIMARY KEY NOT NULL, type TEXT NOT NULL ); SQL $dbh->do(" INSERT INTO type VALUES (1,'foo')" );; $dbh->do(" INSERT INTO type VALUES (2,'bar')" ); $dbh->do( <<SQL ); CREATE TABLE type2 ( id INTEGER PRIMARY KEY NOT NULL, type TEXT NOT NULL ); SQL $dbh->do("INSERT INTO type2 VALUES (1,'foo')" ); $dbh->do("INSERT INTO type2 VALUES (2,'bar')" ); $dbh->do( <<SQL ); CREATE TABLE has_many ( user INTEGER NOT NULL, key TEXT NOT NULL, value TEXT NOT NULL, PRIMARY KEY (user, key) ); SQL $dbh->do( <<SQL ); CREATE TABLE schedule ( id INTEGER PRIMARY KEY NOT NULL, master INTEGER NOT NULL, date DATETIME NOT NULL, note TEXT NOT NULL ); SQL $dbh->do( <<SQL ); CREATE TABLE manager ( id INTEGER PRIMARY KEY NOT NULL, name TEXT NOT NULL ); SQL # Added this table - Shawn $dbh->do( <<SQL ); CREATE TABLE task ( id INTEGER PRIMARY KEY NOT NULL, schedule INTEGER NOT NULL, deadline DATETIME, detail TEXT NOT NULL ); SQL } 1;
package MySchema::Schedule; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ InflateColumn::DateTime Core /); __PACKAGE__->table("schedule"); __PACKAGE__->add_columns( id => { data_type => "INTEGER", is_nullable => 0 }, master => { data_type => "INTEGER", is_nullable => 0 }, date => { data_type => "DATETIME", is_nullable => 0 }, note => { data_type => "TEXT", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( master => 'MySchema::Master' ); # Added this relationship - Shawn __PACKAGE__->has_many( tasks => 'MySchema::Task', 'schedule' ); 1;
package MySchema::Task; use strict; use warnings; use base 'DBIx::Class'; __PACKAGE__->load_components(qw/ Core /); __PACKAGE__->table("task"); __PACKAGE__->add_columns( id => { data_type => "INTEGER", is_nullable => 0 }, schedule => { data_type => "INTEGER", is_nullable => 0 }, deadline => { data_type => "DATETIME", is_nullable => 0 }, detail => { data_type => "TEXT", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( schedule => 'MySchema::Schedule' ); 1;
_______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu