Skip Menu |
 

This queue is for tickets about the Class-DBI-Loader CPAN distribution.

Report information
The Basics
Id: 15220
Status: new
Priority: 0/
Queue: Class-DBI-Loader

People
Owner: Nobody in particular
Requestors: dakkar [...] thenautilus.net
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.22
Fixed in: (no value)

Attachments
CDBI-Loader-bugreport.tgz



Subject: Problems in setting up relationships with loaded classes
Download (untitled) / with headers
text/plain 1.8k
There is a subtle bug using Class::DBI::Loader and many-to-many relationships. The attached tarball contains a test case. To excercise the bug, run 'make.pl' followed by 'test.pl'. 'make.pl' will create a SQLite DB with 3 tables: ai <->> ci <<-> bi 'ci' is the middle table for the many-to-many relation. It will then insert 1 record in each table. 'test.pl' will load the classes with CDBI::Loader, 'require' them to set up relationships, then try to access the 'bi' record associated with the 'ai' record. The error is 'ai is not a column of Bi'. This means that Ai->has_many did not execute correctly. What happens is as follows: - CDBI::Loader creates the three classes, setting up their inheritance tree - Ai calls 'has_many' - CDBI::R::HasMany::remap_arguments calls '_require_class('Ci')' - CDBI::_require_class sees that Ci::ISA exists, and does not 'require Ci' - remap_arguments lacks data to divine the relation columns, and gives wrong results If Ci is required *before* Ai and Bi, everything works, because 'has_a' does not need information extracted from the foreign class. I don't have a way to fix this issue, since it is not really possible to know: - whether the class has been created by CDBI::Loader or by executing the "proper" file - whether relationships will be set up by the file or the loader - what is the right file to require (since it's possible to define several classes in a single source file) The best I can think of is a documentation patch, saying that if someone sets up relationships manually in thei class files, they have to be 'require'd in the correct order after the call to Loader, but before using them. How did I discover it? Catalyst::Model::CDBI requires, in order, the base class that creates the Loader, then the table classes, in alphabetical order. Since my tables are called like 'stuff', 'stuff_thing', 'thing', the relations don't work automatically.
Download CDBI-Loader-bugreport.tgz
application/x-tar 2.2k

Message body not shown because it is not plain text.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.