did you ever get it solved?
The way you have build your model, resourceModel and collection seems to be fine but you did not post your code with which you tried to filter your custom collection.
I ran into problems trying to filter my custom collection within a (foreach)loop today and thought I'd post my code here to show where I got stuck and what the right way to filter is if you need to filter multiple times.
I have a table, a model, a resourceModel and a collection pretty much like yours. My custom model is called Items (there fore I need to use ItemsFactory, see note below) and I collect the manufacturer data in manufacturerData. In my class CustomAction (extending from \Magento\Framework\App\Action\Action) my construct funcion looks like this:
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Vendor\MyCustomModule\Model\ItemsFactory $itemsFactory, // this is my factory
\Magento\Eav\Model\Entity\Attribute $entityAttribute
)
{
$this->_itemsFactory = $itemsFactory;
$this->_entityAttribute = $entityAttribute;
return parent::__construct($context);
}
I needed to filter my custom collection on a custom attribute (or column name if you like) within a foreach loop and this is where I got stuck:
public function execute()
{ ...
$items = $this->_itemsFactory->create();
$collection = $items->getCollection(); // my custom collection
foreach($manufacturerData->getOptions() as $option) {
... // code to get what I need from manufacturer data and find it in my custom_attribute column in my custom collection:
$item = $collection->addFieldToFilter('custom_attribute', $manufacturerAttributeId);
var_dump($item->getData());
}...
To my surprise it would always print the same item (the first item in the collection that was successfully found by the function). It turns out that I should not reuse the collection but simply create and (at the same time) filter WITHIN the foreach-loop:
foreach($manufacturerData->getOptions() as $option) {
... // code to get what I need from manufacturer data and find it in my custom_attribute column in my custom collection:
$item = $this->_itemsFactory->create()->getCollection()->addFieldToFilter('custom_attribute', $manufacturerAttributeId);
var_dump($item->getData());
}
Now I got the right data filtered from my custom collection!
A note on custom collections and -Factory: My items collection has namespace and extends from:
namespace Vendor\MyCustomModule\Model\ResourceModel\Items;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
So there fore this generates a "factory" in generated/code/vendor_name/module_name/Model/class_model_name_Factory.php so my collection factory (since my model class is called "Items") would be ItemsFactory as you can see in the above __construct function where I import \Vendor\MyCustomModule\Model\ItemsFactory $itemsFactory.
So for filtering your custom Collection using addFieldToFilter with your custom column name don't forget to use class_model_name_Factory.