Where might I find out more about the Class::DBI method ->sth_to_objects? Or if there is no documentation out there, does anyone know how it works, and whether it can be used to create two objects, each of a different class?
The method is referenced in the Class::DBI docs and in a Cookbook recipe on the Class::DBI wiki as the method to call at the end of custom SQL queries. But I couldn't find documentation for it in any of the Class::DBI modules on CPAN or on the wiki or in a Google search.
The context is that I am looking at replacing chunks of my hand-rolled persistence abstraction layer with Class::DBI, but before I try that I want to find out as much as I can about how easy and powerful C::DBI can or cannot be when one drops down to hand-crafted SQL. I do a lot of JOINs, sometimes with more than two tables.
I came across this function when researching the first specific question I am trying to answer, which is how I could use Class::DBI to construct two distinct objects out of a single JOIN. Given a particular cookie ID, I want to join the appropriate cookie row with the approriate row from the user table, create one cookie and one user object (pretty simple stuff).
Right now, in my ::Cookie class, I override the ->load method in my hand-rolled persistence class but can still use my persistence class -- first to initialize the objects and then to turn the row returned by the DB into objects (through two other methods, which happen to me named ->load_init and ->load_import). The persistence class also provides me with methods to pull out a list of default fields for each class and the name of the tables for each class so I can use this information (if needed) in crafting the SQL query.
I am worried if I adopt Class:DBI, I won't be able to get this much support around my custom SQL queries. Poking around through the documentation and the wiki, I'm not sure there's even a way to get a list of columns out of Class::DBI to use in my custom SQL query. (If I decide I want an extra column loaded when I pull up a cookie, I don't want to have to update my code in more than one place.)
In reply to Class::DBI method sth_to_objects by ryantate
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |