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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.