[Dbix-class] Newbie question

Jess Robinson castaway at desert-island.me.uk
Mon Mar 16 10:06:16 GMT 2009


On Sun, 15 Mar 2009, Andreas Mock wrote:

> Hi all,
>
> I digged around the provided manuals for DBIC, but there is one (besides others of course ;-) ) things
> I don't understand at the moment:
>
> Where is the mapping done/declared between the attributes of a business object and the attributes
> of the row object returned by a ResultSet?

Business object? Care to explain what you mean by that? Examples?

> Which class or instance of it creates the business objects when getting it from database?
> Is this part of DBIC or does DBIX just ends there?
> Or (what is likely) do I just miss something?

Taking a wild guess:

   $schema->resultset('Books');

returns rows with attributes defined in the Result class Book.pm

   $schema->resultset('Books')->search_related('author');

returns rows with attributes defined in the Result class Author.pm

   $schema->resultset('Books')->search({}, { prefetch => 'author'});

returns rows with attributes defined in Book.pm, AND related objects 
defined in Author.pm

Any call based directly on Books will return Book objects, if you add cols 
with columns, or select/as, its still a Book-based object. If you switch 
sources by search_related to another resultset, that is the one the 
results are based on.

Is that what you meant?

Jess




More information about the DBIx-Class mailing list