Re: setting up relationships

[prev] [thread] [next] [Date index for 2004/06/22]

From: Tony Bowden
Subject: Re: setting up relationships
Date: 07:41 on 22 Jun 2004
On Mon, Jun 21, 2004 at 11:34:31PM -0700, steve shapero wrote:
> I've studied your email several times now and messed around with my 
> code to try out my understanding.  i finally get what this moniker 
> business is all about.  note to documentation writers: it is implied 
> (if i am finally actually getting a clue here) that you have named 
> columns in your database according to this rubric.  or rather, the wise 
> man will name his columns according to this rubric.  the foolish man 
> will insist on confusion by using whatever naming convention his old 
> russian app developer taught him as a young man.

Class::DBI should only be falling back on the moniker for relationships
if you haven't set up your reciprocal has_a relationships. If you have,
then it will use those instead.

So if you have

CD->has_a(artist_id => Artist);

then when you do

Artist->has_many(cds => CD);

It will know that the linking column is 'artist_id'. If you don't have
that has_a() it will assume that it is simply 'artist'.

To avoid the confusion, just ensure that you have your has_a() set up.


> to me, it is rather profound that there is some english language 
> interpolation going on based on how you name things.  call me slow but 
> this is in no way obvious from the documentation and ends up being 
> really confusing to those of us who insist on doing everything the hard 
> way (i.e. their own way).  

This is in the documentation for has_many:

  When setting up the relationship we examine the foreign class's has_a()
  declarations to discover which of its columns reference our class.
  (Note that because this happens at compile time, if the foreign class
  is defined in the same file, the class with the has_a() must be defined
  earlier than the class with the has_many(). If the classes are in dif-
  ferent files, Class::DBI should be able to do the right thing). If no
  such has_a() declarations can be found, or none link to us, we assume
  that it is linking to us via a column named after the moniker() of our
  class. If this is not true you can pass an additional third argument to
  the has_many() declaration stating which column of the foreign class
  references us.

Feel free to supply patches to make the documentation clearer!

Tony

(message missing)

setting up relationships
steve shapero 19:30 on 21 Jun 2004

Re: setting up relationships
Yuval Kogman 20:40 on 21 Jun 2004

Re: setting up relationships
steve shapero 23:34 on 21 Jun 2004

Re: setting up relationships
Yuval Kogman 00:16 on 22 Jun 2004

Re: setting up relationships
steve shapero 06:34 on 22 Jun 2004

Re: setting up relationships
Tony Bowden 07:41 on 22 Jun 2004

Re: setting up relationships
steve shapero 17:28 on 22 Jun 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52