5
我无法读取已加入的另一个表的列。它抛出AttributeError的Peewee在加入后获取列
class Component(Model):
id = IntegerField(primary_key=True)
title = CharField()
class GroupComponentMap(Model):
group = ForeignKeyField(Component, related_name='group_fk')
service = ForeignKeyField(Component, related_name='service_fk')
现在查询是
comp = (Component
.select(Component, GroupComponent.group.alias('group_id'))
.join(GroupComponent, on=(Component.id == GroupComponent.group))
)
for row in comp:
print row.group_id
现在,我得到一个错误AttributeError: 'Component' object has no attribute 'group_id'
行有ATTRS'id'和'title',你是什么意思是由'group_id'? – hyades 2014-09-25 12:38:08
在'select'我已经添加了'GroupComponent.group.alias('group_id')''所以我想要得到'group_id'的值 – Rishabh 2014-09-25 14:00:31