[CDBI] question about set_sql and iterators

Bill Moseley moseley at hank.org
Thu Nov 19 14:09:34 GMT 2009


On Thu, Nov 19, 2009 at 4:45 AM, <arnim.rupp at lhsystems.com> wrote:

> > I don't think you've really understood how object-relational mappers
> > work.
>
> i would say it's more a question if there can be just one database-table
> in one class. as soon as I use set_sql to select from 2+ tables that's
> not the case anyway.
>

Yes, one class is one "table", but there's lots of options.

You could define a view in your database and then create a class for the
view just like any other table.  Probably won't be able to update w/o more
database help.

You can create very complex queries with set_sql, and use TEMP columns as
pointed out.  IIRC, you don't even need TEMP column if you pass the object
to something like Template Toolkit (which I hope you are) because it can
treat it like a hash.  That should drive OO purest nuts.

If you don't care about relationships and just want to display the result
you can use set_sql and then get an $sth with $object->sql_<name used in
se_sql> and then use standard DBI and return whatever data structure you
want.  I do that all the time for complex pages that need to be optimized
for speed.

If you need all the relationships you can use the above to fetch $sth and
normal DBI and then construct your objects however you wish (Yes, I've done
this).

Finally, there's Class::DBI::Sweet where you can specify prefetch similar to
DBIx::Class that wlll do the joins for your and build the objects.  This is
useful if your custom SQL is really there just for the join.
Class::DBI::Sweet adds a lot of useful features somewhat similar to
DBIx::Class but with CDBI you still have lazy column loading and things like
$cd->artist->id won't trigger a separate database query.



-- 
Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digitalcraftsmen.net/pipermail/classdbi/attachments/20091119/45c41a1f/attachment.htm 


More information about the ClassDBI mailing list