Re: Stuck - Join limitation in 1.2?

2007-06-12 Thread Joshua Benner





(Thanks for the note about my article -- I cleaned up the wording a
little to cause less confusion)

I thought along the exact same lines, thinking that belongsTo would
better be referred to as hasOne, until I realized that I was getting
stuck on how I assumed the semantics worked, according to how I would
express the relationships in words. For me, the understanding all
hinged on the concepts of ownership, and which action is "active":
having or belonging (by active I mean doing the pointing -- referencing
the other table with a field).

You seem to be looking at relationships from the perspective of
knowledge -- which object knows about
the other. If this were the case, then your argument about the Thing
not knowing anything about the Person would stand -- but CakePHP and
most relational systems don't look at associations from that
perspective, but rather from an ownership perspective.

Remember this concept: Ownership is a property of the possession.
That is to say, that the secondary or associated data is responsible
for referencing the primary data, not the other way around. The possession
belongs to the possessor. The possession is the item
"doing" something -- the belonging.  So then, the possessor is
passive in the relationship. Ownership is passive, whereas membership
is active. This is why it is the duty of the table with the possession
to reference the table of the possessor. Having is best thought
of as a passive state -- the table that "has" does not reference the
tables who relate to it.

If you're describing the relationship of a Person owning a Thing, since
ownership is a property of the possession, the Thing will
belongTo the Person (having a field in the Thing table which references
a person). And conversely, the Person has(One|Many) Thing(s).

Your implementation will always be dictated by the parameters within
which you are operating. So if you're writing an app in an environment
that describes the data differently than CakePHP's conventions -- you
do what you have to do. But this does not mean that the semantics of
the associations CakePHP applies are incorrect, but perhaps from a
different perspective.

-- 
Joshua Benner
http://bennerweb.com

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php?hl=en  -~--~~~~--~~--~--~---





Re: Stuck - Join limitation in 1.2?

2007-06-12 Thread Nick

Thanks for the reply Joshua

On Jun 12, 8:21 pm, Joshua Benner <[EMAIL PROTECTED]> wrote:
> To, it sounds like:
>
> Person belongsTo Country
>
> I'd use a belongsTo relationship in the Person model.

Correct, this was a bad example, and in this case I'd tend to agree
and that type of relationship does work. Replacing "Country" with
"Thing", and considering that each person has a "Thing" is closer to
what I was thinking. "Things" know nothing about people, and are just
things. Each person will always have just one thing, so we don't need
the flexibility of a join table to associate an arbitrary number of
Things with a person.  A belongsTo relationship will do the job but
seems incorrect as in this case a Person has a Thing, and a Person
does not belong to a Thing. What is the case though is that the actual
value in the Thing column of a Person does belong to Things, and if we
consider that then it does make sense. So whilst Person as a whole
does not belong to Thing, the Thing *value* of a Person does belong to
Thing.

Another example would be Colour, where all manner of models might have
Colour as an attribute, but the models would not belong to colour.

> I wrote a bit on understanding the practical differences between
> relationships here:http://bennerweb.com/node/16

This is a great article, although you show why there is the confusion
when you write

"each movie has one director" but then model that relationship with
belongsTo and not hasOne :) Aside from the fact that belongsTo would
work and hasOne wouldn't, as a movie is the creative work of a
director it would be fair enough to consider that a movie belongs to a
director, but in some cases I feel that hasOne would be the clearer
and more natural choice as this is how we would explain the model to
someone.

It's evidently unnecessary for an enhancement to hasOne, however for
the sake of expressiveness, being able to use hasOne or perhaps an
"isA" concept might be clearer.

Thanks again for the helpful reply though.

Nick


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Stuck - Join limitation in 1.2?

2007-06-12 Thread Joshua Benner

To, it sounds like:

Person belongsTo Country

I'd use a belongsTo relationship in the Person model. And if you need to 
do Country->People lookups, put a reverse hasMany in the country model.

I wrote a bit on understanding the practical differences between 
relationships here:
http://bennerweb.com/node/16

Nick wrote:
> Hi
>
> We're exploring CakePHP, and I'm stuck on how to describe the
> following model relationship. It should be trivial and I'm sure that
> I'm missing something, but precisely what eludes me. Can anyone help?
>
> Let's say that we have a model 'Person', and one of the attributes for
> Person is "country". The value of country is the primary key into a
> table of Countries. $hasOne can express that Person should join on
> Countries, but the join is made against Person.id, and I cannot find a
> way to express that the field in Person to use for the join is
> country.
>
> Checking the archives, floepi posted a tweak back in January to add an
> associatedKey attribute for $hasOne to express this notion, but I
> wondered whether something like this is now standard in 1.2.
>
> Cheers
> Nick
>
>
> >
>   

 
-- 
Joshua Benner
http://bennerweb.com


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Stuck - Join limitation in 1.2?

2007-06-12 Thread Nick

Hi

We're exploring CakePHP, and I'm stuck on how to describe the
following model relationship. It should be trivial and I'm sure that
I'm missing something, but precisely what eludes me. Can anyone help?

Let's say that we have a model 'Person', and one of the attributes for
Person is "country". The value of country is the primary key into a
table of Countries. $hasOne can express that Person should join on
Countries, but the join is made against Person.id, and I cannot find a
way to express that the field in Person to use for the join is
country.

Checking the archives, floepi posted a tweak back in January to add an
associatedKey attribute for $hasOne to express this notion, but I
wondered whether something like this is now standard in 1.2.

Cheers
Nick


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---