Hello all,
Please help me get this working right in Rose,
CREATE TABLE a (
id serial primary key,
name text
);
CREATE TABLE b (
id serial primary key,
a_id integer,
archived_at timestamp
UNIQUE KEY (a_id, archived_at)
);
What I am trying to express here is that "a" is related to many "b"
records, by the a_id foreign key stored in the "b" table. I keep a
unique key on the "b" table that allows me to make a deterministic
one-to-one join for an "a" with it's current "b" record (the one that
is not archived).
So a call like this works to give me "a" and all related "b" records
SELECT * FROM a JOIN b ON (b.a_id=a.id)
And a call like this works to give me "a" with just it's current "b" record
SELECT * FROM a JOIN b ON (b.a_id=a.id) WHERE b.archived_at IS NULL
How should I model this in Rose to work properly?
Currently, I am creating the following relationships in A
relationships =>
[
bs =>
{
type => 'one to many',
class => 'My::B',
column_map => { id => 'a_id' },
},
b =>
{
type => 'one to one',
class => 'My::B',
column_map => { id => 'a_id' },
manager_args=> { archived_at => undef },
},
]
Calling $a->b and $a->bs works as expected, but trying to update $a->b
with a new record simply overwrites the existing "b" record with new
data.
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?
-------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object