when use morph_to relation, can't use where_has to filter
li-linfeng opened this issue · comments
nervermore commented
I have to model, AdminAuth , Services and Works
The relations are below:
-
AdminAuth
id
source_type
source_id -
Services
id -
Works
id
the source_type has two:
"company"--Services ,
"work"---Works
class AdminAuth(Model):
__table__ = 't1_admin_auth'
__casts__ = {
'latest_check_time': 'str',
}
# relations
@morph_to
def source(self):
return
class Services(Model):
__table__ = 'service'
__morph_name__ = 'company'
@scope
def active(self, query):
return query.where('active', 1).where('state', 1).where('isPay', 1)
@morph_one('t1_admin_auth')
def adminAuth(self):
return AdminAuth
now , if i use
AdminAuth.where('source_type', 'company').with_('source').paginate()
i can get correct response, but if i need to filter some servcies, like this:
adminAuth = AdminAuth.where('source_type', 'company').where_has('source', lambda q: q.where('status', 1)).paginate()
or
adminAuth = AdminAuth.where('source_type', 'company').has('source').paginate()
both of them are wrong, the exception shows:
orator.exceptions.query.QueryException: (1054, "Unknown column 't1_admin_auth.None' in 'where clause'")
(SQL: SELECT COUNT(*) AS aggregate FROM `t1_admin_auth` WHERE `source_type` = %s AND
(SELECT COUNT(*) FROM `t1_admin_auth` WHERE `t1_admin_auth`.`source_id` = `t1_admin_auth`.`None`) >= %s
(['company', 1]))
it seems the sql is wrong ,so if there is an way to slove my problem?