[Dbix-class] Newbie question

Ian Wells ijw at cack.org.uk
Mon Mar 16 12:30:37 GMT 2009


2009/3/16 Andreas Mock <andreas.mock at drumedar.de>:
>> Taking a wild guess:
>>
>> $schema->resultset('Books');
>>
>> returns rows with attributes defined in the Result class Book.pm
>
> Ha, there it is again...rows... ;-)

I think you're approaching the question from the other end to how
DBIx::Class tends to represent it.

DBIx::Class tends to think of what you get back as an object
representing a row in the DB, which represents a concept (e.g. a
book).

You sound like you're coming from a .NET or Java background where you
think of the database is a stored representation of an object which
represents a book.

It's much the same thing in the end.

> Are these rows "Book"-Objects???

Yes.

> Or do I have to use these row-objects with Book-attributes to initialize/instanciate
> a Book-Object. (an object with other methods besides methods usfull for persistence)
> Or is this by convention the same?

You get a resultset, which you can loop over to get individual Book
result objects, and result object (a) represents a book and (b) is a
loaded version of a database row in the Book table.

The Book object type can be changed: you can add additional methods
and properties to the book by changing the object's code.  So the
objects that work with DBIx::Class are not *only* for DBIx::Class use,
you can add business logic there too.

Cheers,
-- 
Ian.



More information about the DBIx-Class mailing list