Join statement raises StopIteration exception
NikolaJankovic opened this issue · 1 comments
I'm attempting to run a search on a table and when registering the table I want to include not only columns on the table, but relationships as well. For example if I have an 'Item' column with a one-many relationship with the 'tags' column of my 'Hashtags' table, I want the search to include the related tags. I've tried doing this by simply including the relationship property in the whooshee model registration, as well as creating a hybrid property and expression to represent the related data and included that, however both failed. I moved on to using a join statement, but now that raises a StopIteration exception and I'm unable to decipher why.
Here are the model declarations:
Item
@whooshee.register_model('title', 'description', 'fabric', 'color')
class Item(db.Model):
__tablename__ = 'Items'
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(150))
tags = db.relationship('Tag', backref='item', lazy='dynamic')
@hybrid_property
def all_tags(cls):
return select([Tag.tag]).where(Tag.item_id == cls.id)
@all_tags.expression
def all_tags(cls):
return select([Tag.tag]).where(Tag.item_id == cls.id).label('all_tags')
@hybrid_property
Tags
class Tag(db.Model):
__tablename__ = 'Tags'
id = db.Column(db.Integer, primary_key=True)
tag = db.Column(db.String(120))
item_id = db.Column(db.Integer, db.ForeignKey('Items.id'))
def __init__(self, tag, item_id):
self.tag = tag
self.item_id = item_id
The following code raises the exception:
Item.query.join(Tag).whooshee_search(value).all()
Item.query.join(Item.tags).whooshee_search(value).all()
Without the whooshee_search call the queries return just fine. The specific exception raised is:
*** StopIteration
I think based on what you're describing you're going to need to create a custom whoosheer that would allow you to search across multiple tables - this is one of the cornerstones of how this extension works and is described in [1].
Can you please confirm if this solves your issue?
(Also sorry for the late response, I have a lot on my plate ATM)
[1] http://flask-whooshee.readthedocs.io/en/latest/#how-it-works