Arasu
Arasu

Reputation: 2148

Symfony propel criterion inside for loop

$record_values = new Criteria();
$record_values->add(TblfieldsPeer::CUSTOMER_ID, $company_qu_id);
$record_values->add(TblfieldsPeer::RECORD_TYPE_ID, $query_rtype);
for($fieldid_arrayCount=0;$fieldid_arrayCount<count($fieldIds);$fieldid_arrayCount++)
{
$currentFieldId = $fieldIds[$fieldid_arrayCount];
if(isset($query_values[$fieldid_arrayCount]))
{
$criterion1 = $record_values->getNewCriterion(TblfieldsPeer::FIELDS_ID, $currentFieldId);
$criterion1->addAnd($record_values->getNewCriterion(TblfieldsPeer::FIELD_VALUES, $query_values[$fieldid_arrayCount]));
$record_values->add($criterion1);
}
}
$record_values_results = TblfieldsPeer::doSelect($record_values, $con1);

But only last criterion is added. I check the databases in debug toolbar only the last criterion is there. What could be the problem. Please help me....

Upvotes: 0

Views: 316

Answers (1)

macgyver
macgyver

Reputation: 1279

I'm not a propel expert but maybe you could try to use 2 alternative changes:

  • to use addAnd statement instead of add one in $record_values->add($criterion1)
  • to put $record_values->add($criterion1) outside the (of course after) cycle changing $criterion1 in a field outer the cycle and using only the addAnd statement for $criterion1

Upvotes: 1

Related Questions