0

I added 'custom_field' to 'customer_entity' table by using 'db_schema.xml' file and need to save 'some value' in it then I wanted to filter the collection by 'custom_field' value. How can I achieve this ? When I use the below code.

$customer = $this->_customerFactory->create(); $customerData = $customer->getCollection()->addAttributeToFilter('custom_field',array('neq'=>'cleared'))->setOrder('entity_id','ASC')->load(); 

I am getting this error : The "custom_field" attribute name is invalid. Reset the name and try again.

3
  • Hi @shankar, Did you try the filter by using addFieldToFilter like below: $customer->getCollection()->addFieldToFilter('custom_field',array('neq'=>'cleared'))->setOrder('entity_id','ASC')->load(); Commented Feb 1, 2024 at 9:57
  • Hi @Magedivine I tried it but no luck. let me try again Commented Feb 5, 2024 at 13:40
  • This was helped me : gist.github.com/mrkhoa99/f4582535d6124709885521be185894c4 Commented Feb 5, 2024 at 13:43

1 Answer 1

1

You should try using addFieldToFilter instead of addAttributeToFilter because you are working with the database table field rather than a customer attribute.

Please try it once:

$customer = $this->_customerFactory->create(); $customerData = $customer->getCollection()->addFieldToFilter('custom_field',array('neq'=>'cleared'))->setOrder('entity_id','ASC')->load(); 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.