[Dbix-class] foreigns keys, joins, am I doing something stupid?

Chisel Wright chisel at herlpacker.co.uk
Thu Jan 12 17:09:08 CET 2006


On Thu, Jan 12, 2006 at 11:12:48AM +0000, Chisel Wright wrote:
>   $cds = Nipple::Model::NippleDB::Cd->search(
>     {
>         'artist.name' => 'We Are Goth',
>     }
>   );

Ah, two things caused my problem - replying to myself on-list in case
it's any use to anyone:

->search() needs to be explicitly told which joins to use.
A bit odd since I'm using 'artist.name' in the where clause, but adding

 { join => 'artist' }

was the first step in fixin my problem.

The second (apparently) step was to add a belongs_to to the Cd class. I
keep getting myself mixed up with belongs_to() and has_one()

In my mind a cd has_one artist, but I guess you could say a cd
belongs_to an artist.
Of course, removing the incorrect has_one() declaration stopped DBIx
getting confused, and it seems to work now.

Time to try implementing that in my real life application ...

Chiz
-- 
Chisel Wright
e: chisel at herlpacker.co.uk
w: http://www.herlpacker.co.uk/

This is not an automated signature. I type this in to the bottom of every
message. 



More information about the Dbix-class mailing list