Andreas Mock wrote on 2009-03-16:
> Hi all,
> 
> as part of another thread I want to extract the following question
> with a more meaningful subject:
> 
> We do have objects (O) which consist of attribues (A) which are stored
> in a table O with columns A just as DBIC would model it. But we do also
> have sparse attributes (B) (attributes which are very often NULL) which
> are not stored as columns of the "base" table O but as rows of a - let's
> call it attribute table - where each "not null"- attribut B of O is a
> row in that table with a key consisting of a class identifier, an object
> identifier (O.id) and an attribute identifier.
> 
> After loading this object I want to see that object in a flat way. This
> "attribute collection" shall show up as "normal" (columns) attributes
> (with accessors named like the attribute identifier). While using the
> object from the application perspective I don't want to know that there
> are some attributes stored as columns in the base table and some as
> entries in a related table.
> 
> Is there a way in DBIC to do this?
> 
> Best regards
> Andreas Mock
> 

Hi Andreas,

You can add methods to your row class (O) that will fetch and return the data 
from the related table B.  E.g. you can add a $O->sparse_attr() method that 
would return the value of ($O->B || $O->B->value).

Any methods you add to your schema class for table O will be available as 
methods on the row object $O, so you're pretty free to create your own 
interfaes to your business objects and abstract the relationships aways from 
your client code.

Byron


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to