Never mind Re: add_to_ for existing objects
[prev]
[thread]
[next]
[Date index for 2005/04/08]
Never mind, I solved it by doing:
$user->add_to_notes({note_id => $note->id})
... I was misunderstanding add_to_, in a many-to-many relationship add_to_ only
acts on the jump table, not the target object, as it does in a one-to-many.
Cheers
r
On Fri, 8 Apr 2005, Ryan Tate wrote:
> Two of my classes has_many of each other through a jump table. The
> relationships are declared and work fine via Class::DBI.
>
> But I am unable to figure out how to associate an existing object in one
> class with an existing object in the other class using anything but a manual
> create. add_to_ only associates an existing object and a new object, not two
> existing objects with one another.
>
> My relationship looks like:
>
> Dashboard::Note->has_many( users => [ 'Dashboard::Note::User' => 'user_id' ]
> );
>
> Dashboard::Note::User-->has_a( note_id => 'Dashboard::Note' );
> Dashboard::Note::User->has_a( user_id => 'Dashboard::User' );
>
> Dashboard::User->has_many( notes => [ 'Dashboard::Note::User' => 'note_id' ]
> );
>
> A user might decide to share one of his notes with another user. In this
> case, I need to associate two existing objects.
>
> I guess I can just do a Dashboard::Note::User->create({
> note_id => $note->id,
> user_id => $user->id
> });
>
> ... which isn't really all that hard at all, but was wondering if there was
> another way. I saw this issue raised in
>
> http://groups.kasei.com/mail/arc/cdbi-talk/2004-09/msg00070.html
>
> and it sounds like what I am asking for is not available but the ultimate
> answer ( http://groups.kasei.com/mail/arc/cdbi-talk/2004-09/msg00078.html )
> left me unsure.
>
> Would a patch to add_to_ be welcome, to allow it to distinguish between
> existing objects and hashrefs for new objects?
>
> Cheers
> RT
>
>
|
Never mind Re: add_to_ for existing objects
Ryan Tate 20:18 on 08 Apr 2005
|