[Dbix-class] Using and inter-linking multiple databases via DBIC:
"Can't find source"
Henry Van Styn
vanstyn at cpan.org
Fri Oct 18 19:13:05 GMT 2013
On 10/18/2013 1:26 PM, will trillich wrote:
> We are using Catalyst for a web app. We've split off the =
> authentication database to facilitate multiple different apps using =
> the same user credentials, but we're having trouble linking the auth =
> db to the biz-info db.
>
> The generalized user/team credentials and related info are in Auth, =
> and the actual business info for this app is in DB. Here's an object =
> from the DB database:
>
>
> package Learn::Schema::DB::Result::TeamEmail;
> #...
> __PACKAGE__->belongs_to( team =3D> 'Learn::Schema::Auth::Result::Team' );
>
>
> Note that we're trying to get DB::TeamEmail to refer to Auth::Team =
> here. And below is the related object from the Auth database:
>
>
> package Learn::Schema::Auth::Result::Team;
> #...
> __PACKAGE__->has_many( emails =3D> =
> 'Learn::Schema::DB::Result::TeamEmail', 'team' );
>
>
> At this point we expect
>
> *$team->emails_rs*
>
> to work but instead we get
>
> Can't find source for Learn::Schema::DB::Result::TeamEmail
>
> because TeamEmail isn't in $self->source_registrations (full names) or =
> $self->class_mappings (brief names) in the =
> DBIx::Class::Schema::source() method.
>
>
> Pointers? Is there a different approach? Got a clue stick?
>
>
You probably just need to load the additional result classes into your =
schema.
Assuming you are using the typical __PACKAGE__->load_namespaces call in =
your Schema class, you can call it with parameters to find classes under =
multiple namespaces. Something like this in your Learn::Schema::DB:
__PACKAGE__->load_namespaces(
result_namespace =3D> [ '+Learn::Schema::Auth::Result', 'Result' ],
resultset_namespace =3D> [ =
'+Learn::Schema::Auth::ResultSet','ResultSet' ],
);
See https://metacpan.org/module/DBIx::Class::Schema#load_namespaces for =
more details
You will also probably need to make sure you use 'dbname.tablename' =
instead of just 'tablename' in the __PACKAGE__->table() call in your =
result classes. If you're using Schema::Loader, see the =
'qualify_objects' option to have this generated automatically:
https://metacpan.org/module/DBIx::Class::Schema::Loader::Base#qualify_objec=
ts
Hope this helps,
vanstyn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20131018/54d=
4fe4a/attachment.htm
More information about the DBIx-Class
mailing list