I've got two tables, book
and language
; book
belongs_to
language
by having a language
column stating which language it's in. The language
table is just the language
column.
I want to do $book->language
and get the language string, without fetching the language from the language
table. Is there a way to do that?
I suspect it's about return context. Should I do some sort of overload, say:
use overload "language_string" => sub {
my $self = shift;
return $self->language;
}, fallback => 1;
But in that case I'm, of course, still getting the language.
One solution is to define the relationships with different names than the columns e.g. rel_$colname
.
Then the accessor methods generated by DBIC will be different for the column value and the related object(s).
If you don't want to change your relationship names you can always access the column value with $row->get_column('colname');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With