That's a pretty cool approach, and it solves adding a new record smoothly. But what it misses is the ability to fetch all a that have a non-archived b:
SELECT * FROM a JOIN b ON (b.a_id=a.id) WHERE b.archived_at IS NULL or My::A::Manager->get_as_iterator(requre_objects => [ 'b' ]); Here's another approach: Store a foreign key on A for the one-to-one CREATE TABLE a (id pri key, b_id foreign key); and store a foreign key on B for the one-to-many CREATE TABLE b (id pri key, name text, a_id foreign key) But I tried this before and I ran into a lot of trouble mapping IDs back-and-forth, eg. If you set $a->b({ name => 'test' }), will Rose know to map the b back to the a as well as mapping the a to the b? Which is a cleaner approach? On 5/18/07, John Siracusa <[EMAIL PROTECTED]> wrote: > On 5/18/07, Derek Watson <[EMAIL PROTECTED]> wrote: > > Am I modeling this wrong? How can I get Rose to archive the previous > > $a->b when I say $a->b($new_b_record)? Or at least try to save the new > > 'b' record so that my DB will throw an error about a clashing unique > > key? > > A ...-to-one expects there to just be one thing at the end. So > there's no "add" method, just get and set. A set implies replacing > the existing one with a new one, which is what you're seeing: RDBO > deletes the old and inserts the new. > > To get the behavior you want, I think you'll need to use a 1-to-many > and then wrap the relationship accessor in such a way that a set is > really an add. > > sub b > { > my($self) = shift; > > $self->add_bs(@_) if(@_); > > # bs must be sorted so that the last one is the latest one > # use manager_args on the "bs" rel to do that. > my $bs = $self->bs || []; > > return $bs->[-1]; > } > > Then add a trigger to the b table (or the My::B class) to handle the > "archiving" or a previous b record when a new one is inserted. > > -John > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Rose-db-object mailing list > Rose-db-object@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rose-db-object > ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Rose-db-object mailing list Rose-db-object@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rose-db-object