in CDBI (+Sweet), i would do something like this:
Category->has_many(
messages => [ 'CollectionMessage' => 'message' ],
constraint => { 'message.atype' => 'discussion',
'message.pubstatus' => 'published' }
);
sub latest_message {
my $self = shift;
my ($latest) = $self->messages({ order_by => 'pubdate DESC',
rows => 1 });
return $latest;
}
the closest i have come up with in RDBO is:
Category->meta->setup(
# ...
relationships => [
messages => {
type => 'many to many',
map_class => 'CollectionMessage',
map_from => 'category',
map_to => 'message',
query_args => [ 'message.atype' => 'discussion',
'message.pubstatus' => 'published' ]
},
latest_message_map => {
type => 'many to many',
map_class => 'CollectionMessage',
map_from => 'category',
map_to => 'message',
query_args => [ 'message.atype' => 'discussion',
'message.pubstatus' => 'published' ],
manager_args => { sort_by => 'message.pubdate DESC',
limit => 1 }
}
]
);
sub latest_message {
my $self = shift;
my $latest = $self->latest_message_map;
return $latest && $latest->[0];
}
i guess i have three questions.
1. is there a way to pull that off with 'one to one' type
relationship so i can drop the subroutine?
2. or is there a way to tack on extra conditions (or custom ordering)
to existing relationships, so i can keep the subroutine and drop the
extra relationship?
(what Class::DBI calls Limiting: http://search.cpan.org/~tmtm/Class-
DBI-v3.0.16/lib/Class/DBI.pm#Limiting )
3. am i missing some other RDBO magic that would make this easier?
---
michael reece :: software engineer :: [EMAIL PROTECTED]
-------------------------------------------------------------------------
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