6

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.

daxim
  • 39,270
  • 4
  • 65
  • 132
Jon
  • 188
  • 1
  • 8

1 Answers1

6

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');

Colin Newell
  • 3,073
  • 1
  • 22
  • 36
Alexander Hartmaier
  • 2,178
  • 12
  • 21