On Thursday, July 05 2007 02:06 pm, Henry Baragar wrote: > On Thursday, July 05 2007 10:29 am, Sean E. Millichamp wrote: > > Henry Baragar wrote: > > > I have not be able to figure out why it does this, but I can tell you > > > that it does not list "customer_id" twice if the "refers_to" is > > > removed, nor if the column is named something else (such as > > > "customer_di"). > > > > There is internal Jifty magic with column names ending in "_id". You > > can add an _id to a refers_to column to get the actual numerical ID back > > instead of the actual object. As a result, you can't name refers_to > > columns with an ending of "_id", things get confused. > > I thought the magic was more along the lines that if your column name ends > in "_id", then Jifty magically creates a method with the same name as the > column, but with out the trailing "_id", that will return the object for > you. > > I have provided a sample below that tests things both ways, and I get > errors if the refers_to column name does not end in "_id". Given this > behaviour, then I think there is a problem in what columns returns. > > Am I mistaken? > > > This bit me for hours once a long time ago and, now that I'm thinking > > about it, I don't think I ever contributed a documentation patch. Shame > > on me :(. > > This had confused me before as well. I am not sure I understand things > well enough to improve the documentation. > > Henry > > > I don't have time to craft one at the moment, but if you do I'm sure it > > would be welcomed. > > > > Sean > > > > _______________________________________________ > > jifty-devel mailing list > > jifty-devel@lists.jifty.org > > http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel >
Account.pm ======= use strict; use warnings; package Test::Model::Account; use Jifty::DBI::Schema; use Test::Record schema { column name => type is 'varchar(20)', ; column customer_id => type is 'integer', refers_to Test::Model::Customer, ; }; # Your model-specific methods go here. 1; Customer.pm ======== use strict; use warnings; package Test::Model::Customer; use Jifty::DBI::Schema; use Test::Record schema { column name => type is 'varchar(20)', ; column account => type is 'integer', refers_to Test::Model::Account, ; }; # Your model-specific methods go here. 1; 01-model-refers_to.t ============ #!/usr/bin/env perl use warnings; use strict; =head1 DESCRIPTION A basic test harness for the Account model. =cut use Jifty::Test tests => 6; # Make sure we can load the model use_ok('Test::Model::Account'); use_ok('Test::Model::Customer'); # Grab a system user my $system_user = Test::CurrentUser->superuser; ok($system_user, "Found a system user"); # Try testing a create my $ref_a = Test::Model::Account->new(current_user => $system_user); $ref_a->create(name => "refered to account"); my $ref_c = Test::Model::Customer->new(current_user => $system_user); $ref_c->create(name => "refered to customer"); my $a = Test::Model::Account->new(current_user => $system_user); $a->create(name => "account"); my $c = Test::Model::Customer->new(current_user => $system_user); $c->create(name => "customer"); $a->set_customer_id($ref_c->id); $c->set_account($ref_a); is($c->account->name,"refered to account","Got refered to account name"); is($a->customer->name,"refered to customer","Got refered to customer name"); is($c->account_id,$ref_a->id,"Customer refers to the correct account id"); prove -vl t/01-model-refers_to.t =================== t/01-model-refers_to....1..6 ok 1 - use Test::Model::Account; ok 2 - use Test::Model::Customer; ok 3 - Found a system user Can't locate object method "account_id" via package "Test::Model::Customer" at t/01-model-refers_to.t line 37. # Looks like you planned 6 tests but only ran 5. ok 4 - Got refered to account name ok 5 - Got refered to customer name dubious Test returned status 255 (wstat 65280, 0xff00) DIED. FAILED test 6 Failed 1/6 tests, 83.33% okay Failed Test Stat Wstat Total Fail List of Failed ------------------------------------------------------------------------------- t/01-model-refers_to.t 255 65280 6 2 6 Failed 1/1 test scripts. 1/6 subtests failed. Files=1, Tests=6, 2 wallclock secs ( 0.91 cusr + 0.08 csys = 0.99 CPU) Failed 1/1 test programs. 1/6 subtests failed. _______________________________________________ jifty-devel mailing list jifty-devel@lists.jifty.org http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel