You could use hybrid attributes to do that.

http://docs.sqlalchemy.org/en/rel_0_7/orm/extensions/hybrid.html

On Wednesday, August 29, 2012 5:22:02 PM UTC+9, Denis Rykov wrote:
>
> I have two models:
>
>     class Report(Base):
>         __tablename__ = 'report'
>         id = Column(Integer, primary_key=True)
>     
>     class ReportPhoto(Base):
>         __tablename__ = 'report_photo'
>         id = Column(Integer, primary_key=True)
>         report_id = Column(Integer, ForeignKey(Report.id), nullable=False)
>         
>         report = relationship(Report, uselist=False, 
> backref=backref('report_photo', uselist=True))
>
> And I would like to add column to Report model which indicates is there 
> any records within ReportPhoto. I try to use [column_property][1] this way:
>
>     class Report(Base):
>         __tablename__ = 'report'
>         id = Column(Integer, primary_key=True)
>
>         has_photo = column_property(
>             select(ReportPhoto.any())
>         )
>
> but get an error `NameError: name 'ReportPhoto' is not defined`. How I can 
> fix this issue?
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/mq1-pGbqYDwJ.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to