add_to_ for existing objects
[prev]
[thread]
[next]
[Date index for 2005/04/08]
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
|
add_to_ for existing objects
Ryan Tate 20:06 on 08 Apr 2005
|