Hi,

I wonder if there is a shortcut for multi level relationships.
I have three tables in a relationship like 'cities', 'states' and 
'countries'. Now I would like to say something like 
print $city->country->name;
I know how to to it in two steps (first get the state then the 
country from there) or with redundency (have an additional country_id 
in cities) but I don't like these alternatives so I tried with 
something like this (in Cities.pm):

__PACKAGE__->meta->relationships(
    state => {
        type       => 'many to one',
        class      => 'MyApp::States',
        column_map => { state_id => 'id' },
    },
    country => {
        type       => 'many to one',
        class      => 'MyApp::Countries',
        column_map => { '__PACKAGE__->state(id => state_id)-
>country_id' => 'id' },
    },
);

but that doen't work, probably because state is not a class method 
and I don't have an object yet.
Is there some other way I can do it?

Thanks,
Michael

p.s.: After some more experimenting I came up with this object 
method:
sub country {
    my $self = shift;
    my $state = MyApp::States->new(id => $self->state_id)->load();
    my $country = $state->country();
    return $country;
}

This is o.k. for me as a solution but if there is a way to do it the 
"meta->relationship" way I would prefer it because it is more 
readable if everything is in one place.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to