Skip to content

Search for one-to-many relationship fails saying 'has()' not implemented for collections. Use any(). #10

@hussaintamboli

Description

@hussaintamboli
class Product(Model):
    __tablename__ = 'product'
    ...
    usecase = relationship("ProductUsecaseMapping", cascade="save-update", lazy="joined")

class ProductUsecaseMapping(Model):
    __tablename__ = 'product_usecase_mapping'
    product_id = Column(String(36), ForeignKey('product.id'))
    usecase_id = Column(Integer, ForeignKey('usecase.id'))
    ....

filter_for_searching_specific_products = {
    'filter': {
        'country_code': kwargs.pop('country'),
        'category': kwargs.get('search_type'),
        'usecase.usecase_id': {
            'in': [kwargs.pop('usecase')]
        }
    }
}

It works for one-to-one relationship but not with one-to-may. With above filter I get an error saying -

'has()' not implemented for collections.  Use any().

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions