Re: [CDBI] question about set_sql and iterators
"Edward J. Sabol" <[email protected]> Wed, 18 Nov 2009 11:34:52 -0500
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
> i don't manage to get the results of the columns in table b and I find no
> hint in the documentation. any hints?
I don't think you've really understood how object-relational mappers work.
You defined the SQL using A->set_sql() and then used A->search_*().
Therefore, you are going to get objects of class A. If you want to access
values from B, then you need a B object, like so:
while (my $a_record = $iterator->next) {
print $a_record->id;
my $b_record = B->retrieve($a_record->id);
print $b_record->number; # should work
}
There are other work-arounds. You might be able to get by by adding TEMP
columns to A. Refer to the following CDBI wiki pages:
http://wiki.class-dbi.com/wiki/Query_aggregates
http://wiki.class-dbi.com/wiki/Using_joins
Hope this helps,
Ed
P.S. Your SQL should be "SELECT __ESSENTIAL__ ..." instead of "SELECT * ...".