fix: association proxy results in form_ajax_refs

Builds upon #1906
parent 69a69847
......@@ -69,7 +69,9 @@ class QueryAjaxModelLoader(AjaxModelLoader):
def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE):
query = self.get_query()
filters = (cast(field, String).ilike(u'%%%s%%' % term) for field in self._cached_fields)
# no type casting to string if a ColumnAssociationProxyInstance is given
filters = (field.ilike(u'%%%s%%' % term) if is_association_proxy(field)
else cast(field, String).ilike(u'%%%s%%' % term) for field in self._cached_fields)
query = query.filter(or_(*filters))
if self.filters:
......
......@@ -216,4 +216,6 @@ def is_relationship(attr):
def is_association_proxy(attr):
if hasattr(attr, 'parent'):
attr = attr.parent
return hasattr(attr, 'extension_type') and attr.extension_type == ASSOCIATION_PROXY
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment