[Dbix-class] load_classes question

Rolf Schaufelberger rs at plusw.de
Sun Oct 28 17:10:49 GMT 2007


Hi, 

I have different applications that share a set of common features and thus 
tables and DBIC-classes. 
I want to have my common classes and my application specific classes 
in different namespaces so that Application A can use all common and her own, 
and App. B all common and his own. Relations exist in both directions between 
common and A or common and B.

Now I don't know how to set this up properly.

So currently I have:

MySchema::DB::  *   all common classes 
Site::SiteA::DB:: *  classes from SiteA
Site::SiteB::DB:: *  classes from SiteB
...

Along with this I have different schema classes:

Site::SiteA::DB.pm 
Site::SiteB::DB.pm 

Example:
Common class:
MySchema::DB::Users
..
# no belongs_to  defined
;
----------------------------------------
in Site::SiteA::DB::Company.pm:

package Site::SiteA::DB::Company;
...
has_many(users => 'MySchema::DB::Users' );
-----------------------------------------
and my schema class in   Site::SiteA::DB.pm
package Site::SiteA::DB;
...
__PACKAGE__->load_classes ( qw(Company), {MySchema::DB => [qw(Users)]});
---------------------------------------------
Now caling 
my $c = $schema->resultset('Company')->find(1);
my @users = $c->users;

works, but when I add in Users.pm
belongs_to (company , 'MySchema::DB::Company'); 

I get an error : "Can't locate MySchema/DB/Company.pm"
So far I can understand this.

Now I tried it this way:
in Site::SiteA::DB.pm
package MySchema::DB
...
__PACKAGE__->load_classes ( qw(Users), {Site::SiteA::DB => [qw(Comapny)]});
------------------------------------
again it works as far as there is no belongs_to in Users.pm, but as soon as I 
define this I get the same error again.

So how can I get this to work ? 

I tried to understand load_namesaces, but I don't understand the difference 
between  "result class" and result_set class".

-- 
Regards
Rolf Schaufelberger



More information about the DBIx-Class mailing list