Search code examples
perlrelationshipdbix-class

How to create a row object that contains related objects in DBIx::Class?


When you create a Row object in DBIx::Class you can pass related objects as values, e.g.

my $author = $authors_rs->find(1);
my $book = $books_rs->create({ author => $author, title => 'title' });

However, if you later use the author accessor, the object is retrieved again from the database. Is it possible to create an object so that the associated object can be accessed without the additional query?


Solution

  • How about just copying what you want from $author into some plain old Perl variables?

    If you want to copy a whole structure, the clone module may help (I don't have experience with this module; I just found it online).