[Dbix-class] search using multiple values for the same column
Fernan Aguero
fernan at iib.unsam.edu.ar
Thu Jul 6 16:42:15 CEST 2006
+----[ Will Hawes <info at whawes.co.uk> (05.Jul.2006 14:15):
|
[snipped]
| > my $features = [];
| > while (my $itemfeature = $itemfeatrs->next() ) {
| > push @{$features}, $itemfeature->feature_id;
| > }
| >
| > # and now I should do the following
| > my $featrs = $feat->search( { feature_id => $features } );
| >
| > except that the problem is before this step, because
| > $itemfeature->feature_id
| > is not returning a scalar (the id) but a HASH
[snipped]
| This is because $itemfeature->feature_id gets auto-inflated to a
| "Features" object.
Will, thanks for your reply. I've got taken away by the
sudden appearance of a deadline ... so I've not been able to
test this. I just wanted to give you a quick reply, so as to not
seem unresposive.
Does the inflation occur because of the relationships set up
between tables? This doesn't happen with normal tables and
with 1-to-many relationships between tables.
| If you want just the value, you could access it like this:
|
| $itemfeature->feature_id->feature_id
|
| Alternatively (and possibly more efficiently), you could use
| get_column() to obtain the column value, bypassing inflation completely:
|
| $itemfeature->get_column('feature_id')
OK, I'll try. Right now I've replaced this (cause I needed
to solve it urgently) with good ol' DBI, and writing the SQL
join myself.
| Assuming you are able to alter the database I would also be tempted to
| say structure your tables like this instead to avoid confusion:
|
| TABLE items (id, item)
| TABLE features (id, feature)
| TABLE item_features (item, feature)
|
+----]
More information about the Dbix-class
mailing list