Python Peewee在联接后获取列

Python Peewee在联接后获取列,python,mysql,peewee,Python,Mysql,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_

我无法读取另一个已联接表的列。它抛出了一个错误

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'对象没有属性'group\u id'

如果您只想直接将
group\u id
属性修补到所选的
组件上,请调用
.naive()
。这会指示peewee您不想重建连接模型的图形——您只想将所有属性修补到单个组件实例上:

for row in comp.naive():
    print row.group_id  # This will work now.

行中有attrs
id
title
,您所说的
group\u id
是什么意思?在
select
中,我添加了
GroupComponent.group.alias('group\u id')
,所以我想得到
group\u id