[CDBI] question about set_sql and iterators

Edward J. Sabol Edward.J.Sabol at nasa.gov
Wed Nov 18 16:34:52 GMT 2009


> 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 * ...".



More information about the ClassDBI mailing list