[Dbix-class] more complex relationships
Mark Hedges
hedges at ucsd.edu
Thu Mar 23 18:59:11 CET 2006
On Thu, 23 Mar 2006, Jess Robinson wrote:
>
> I just spent several minutes writing a DBIx::Class schema to handle this,
> and now it's occured to me that we haven't seen what you've tried..
>
> It certainly doesn't look hard at all, so I have a suspicion that you just
> got your relationships mixed up, can you show the code you tried?
>
> Also, whats a product_id? It seems to just exist in vendor_product's
> imagination.. and sale_item has one as well, but I have no idea where they
> are pointing.
>
> .. Anyway, to get a vendor_name from a sale_item, you need to do something
> like:
>
> DB::Schema::SaleItem->belongs_to(sale_id => 'DB::Schema::Sale');
> DB::Schema::Sale->belongs_to(vendor_name => 'DB::Schema::Vendor');
>
> then from a $saleitem:
>
> $saleitem->sale_id->vendor_name
>
> will get you a vendor object
>
> (You can name the relationships however you like)
A vendor_product's product_id is the product_id at the remote
vendor for one of our products that we might be selling there.
We might sell the same product in multiple ways/prices with one
vendor. product_id is arbitrary, it comes from the vendor, but
for every vendor_product, the MCPK of (vendor_name, product_id)
will be unique and defines what it is.
Your example is obvious, but not what I am trying to do. I want
to go from a sale_item to the vendor_product that was sold. I
can't without writing a subroutine for a sale_item to get the
vendor_name from the parent sale, then look up the
vendor_product from that vendor_name and its product_id.
Mark
More information about the Dbix-class
mailing list