У меня есть следующая модель.
Код: Выделить всё
class Sample(MAFwBaseModel):
sample_id = AutoField(primary_key=True, help_text='The sample id primary key')
sample_name = TextField(help_text='The sample name')
class Resolution(MAFwBaseModel):
resolution_id = AutoField(primary_key=True, help_text='The resolution id primary key')
resolution_value = FloatField(help_text='The resolution in µm')
class CalibrationMethod(MAFwBaseModel):
method_id = AutoField(primary_key=True, help_text='The primary key for the calculation method')
multiplier = FloatField(default=1., help_text='The multiplication factor of this method')
class Image(MAFwBaseModel):
image_id = AutoField(primary_key=True, help_text='The image id primary key')
sample_id = ForeignKeyField(Sample, on_delete='CASCADE', backref='+')
filename = TextField()
checksum = TextField()
resolution_id = ForeignKeyField(Resolution,on_delete='CASCADE', backref='+')
class ProcessedImage(MAFwBaseModel):
image_id = ForeignKeyField(Image, primary_key=True, backref='+', help_text='The image id, foreign key and primary', on_delete='CASCADE')
value = FloatField(default=0)
Отношения между изображением и тремя другими таблицами идеальны. как показано в ERD ниже.

Теперь я хочу сделать перекрестное соединение с помощью CalibrationMethod, и для этого я использую следующий запрос.
Код: Выделить всё
cross_join = (ProcessedImage.select(ProcessedImage, CalibrationMethod)
.join(CalibrationMethod, JOIN.CROSS)
.execute()
)
Код: Выделить всё
for row in cross_join:
# the image_id of ProcessedImage is not what I was expecting:
row.image_id # is the row in Image
row.image_id_id # is the field in ProcessedImage
row.method_id # is the field in CalibrationMethod.
Это заставляет меня думать, что это не ошибка, а скорее особенность, которую я упускаю из виду. что-нибудь. Что мне не хватает?
Должно быть, есть страница документации, которую я пропустил.
спасибо за помощь!
toto
Подробнее здесь: https://stackoverflow.com/questions/792 ... to-a-field
Мобильная версия