0

I would like to get a table in the administration which i have the invoices pending from a date

so I create a class with _prepareCollection () function.

In the function I added this statement:

   $now = Zend_Date::now();
   $collection->addAttributeToFilter('dunning_payable_due_on',array('date' => true, 'to' => $now));
   $collection->addAttributeToFilter('state','1');

but I get an error:

Integrity constraint violation: 1052 Column 'state' in where clause is ambiguous

I have to do a join but I don't know with what table.

thanks for your help.

1

You get this error message when the column indicated in the message is present in more than one table in the collection. You should define the table alias in the addAttributeToFilter() call i.e.:

$collection->addAttributeToFilter('main_table.state','1');

Note that as I have no idea what tables are in your collection from the question, so main_table is probably not correct may not necessarily be correct - it's just quite commonly this for the first table in collections. If not then you will need to pull the select object from the collection and inspect it to determine the alias for the table in question:

$from = $collection->getSelect()->getPart('from');
foreach ($from as $alias => $details):
    // $alias is the table alias
    // $details['tableName'] is the table in the database
endforeach;

Go through each table and look for the presence of the state column. Once you have identified the correct table add the alias for that table into the call to addAttributeToFilter().

1
  • ok thanks for your help.so i find the solution, i replaced by : $collection->addAttributeToFilter('invoice.state','1'); – strauss Dec 2 '14 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.