grigri:
Thanks, this is what I had originally thought up:
"Although perhaps you could act as if it was asymmetric, but
synchronize `friendship` table updates : if you create or delete
{subject_id: 1, object_id: 2} then you must simultaneously create/
delete {subject_id: 2, object_id: 1}. You'd get data duplication,
sure, but it might make things easier to manage."
My problem now is saving the data. Lets say I have an action
saveFreindship() and I pass in the parameters for subject_id and
object_id,
how do I set up the save using the model?
For instance if I was using a form it would be as simple as $this-
>User->save($data) but since I am sending the data is as parameters I
can't seem to get it to work.
Again, any help is greatly appreciated.
Thanks,
-Andrew
On Apr 9, 5:25 pm, grigri <[EMAIL PROTECTED]> wrote:
> It depends entirely on whether you want the friendship relation to be
> symmetric or not.
>
> Symmetric: If Fred is Joe's friend then Joe is Fred's friend and vice-
> versa
> Asymmetric: Fred can be Joe's friend regardless of whether or not Joe
> is Fred's friend.
>
> An asymmetric relation would be easier to implement:
>
> table: friendships (id, subject_id, object_id) [person `subject_id`
> regards person `object_id` as a friend]
>
> class Person extends AppModel {
> var $hasAndBelongsToMany = array(
> 'Friend' => array( // People that this person regards as a friend
> 'className' => 'Person',
> 'with' => 'Friendship',
> 'foreignKey' => 'subject_id',
> 'associationForeignKey' => 'object_id'
> ),
> 'Admirer' => array( // People who regard this person as a friend
> 'className' => 'Person',
> 'with' => 'Friendship',
> 'foreignKey' => 'object_id',
> 'associationForeignKey' => 'subject_id'
> )
> );
>
> }
>
> Symmetric relationships would be trickier. As I see it, you'd have to
> use a custom query to retrieve/update/delete the data, and always
> enforce a constraint that (for example) subject_id < object_id [to
> avoid duplicates].
>
> Although perhaps you could act as if it was asymmetric, but
> synchronize `friendship` table updates : if you create or delete
> {subject_id: 1, object_id: 2} then you must simultaneously create/
> delete {subject_id: 2, object_id: 1}. You'd get data duplication,
> sure, but it might make things easier to manage.
>
> Hope this helps - let me know how this progresses, as it's quite an
> interesting subject.
>
> On Apr 9, 10:06 am, dizz <[EMAIL PROTECTED]> wrote:
>
> > Hi all,
>
> > I'm trying to add a friend feature to one of my sites.
>
> > I am trying to wrap my head around how to set up the relationship.
>
> > I have a table users which holds all the users info.
>
> > Each user can have many friends which is just an alias for many users
> > and those friends (users) belong to the User.
>
> > This sounds like a HABTM relation, but how would I go about setting it
> > using the same model?
>
> > Any help would be greatly appreciated.
>
> > Thanks,
> > -Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---