[Dbix-class] more complex relationships

Jonas Alves jonas.alves at co.clix.pt
Fri Mar 24 18:14:19 CET 2006


On Friday 24 March 2006 15:37, Matt S Trout wrote:
> Jonas Alves wrote:
> > On Friday 24 March 2006 14:21, Matt S Trout wrote:
> >> Jess Robinson wrote:
> >>> I'd still like to see the DBIx::Class code..
> >>>
> >>> So, if I read it correctly now, from sale_item, which has a sale_id and
> >>> a product_d, you want to get the entry in vendor_product?
> >>>
> >>> $schema->resultset('VendorProduct')->find({vendor_name =>
> >>>                                     $saleitem->sale->vendor_name,
> >>>                                    product_id =>
> >>>                                      $saleitem->product_id});
> >>> ?
> >>>
> >>> .. so it wants a sort of infinite level relationship search similar to
> >>> how we do it with joins already?
> >>
> >> I think what we're basically looking at here is a relationship that's
> >> only valid on a sort-of-a-view across two tables. So something like
> >>
> >> ->add_relationship('vendor_product', 'My::VendorProduct', {
> >> 'foreign.vendor_name' => 'self.sale.vendor_name', foreign.product_id =>
> >> 'self.product_id' });
> >
> > I also need relationships based in column constant values. eg:
> >
> > ->add_relationship('vendor_product', 'My::VendorProduct', {
> >  'foreign.product_id' => 'self.product_id',
> >  'self.product_reference' => '123'
> > });
>
> ->add_relationship('vendor_product', 'My::VendorProduct',
>    { 'foreign.product_id' => 'self.product_id' },
>    { where => { 'vendor_product.product_reference' => 123 } }
> );

Right! That's it. Thanks Matt. :)



More information about the Dbix-class mailing list