[Dbix-class] has_one over joining table
Stuart Dodds
dodds at united-domains.de
Tue Jan 30 08:42:26 GMT 2018
On 29/01/18 17:31, Andrew Beverley wrote:
> Something like (in Result::Town):
>
> __PACKAGE__->might_have(
> "town_people_mayor",
> "MyApp::Schema::Result::TownPeople",
> sub {
> my $args = shift;
> return {
> "$args->{foreign_alias}.town_id" => { -ident => "$args->{self_alias}.id" },
> "$args->{foreign_alias}.is_mayor" => 1,
> };
> }
> );
>
> You would then do something like:
>
> $town->town_people_mayor->mayor
Hi Andy,
Yes, that works perfectly...thank you!
It would have been nice to do it in one step as I wouldn't need to
change the calling side...but I blame myself for coming up with a shabby
db structure in the first place ;)
Thanks again for your help,
Stuart
More information about the DBIx-Class
mailing list