On Aug 19, 2010, at 6:38 AM, Yap Sok Ann wrote:
> With declarative base, is it possible to use a relationship within a
> column_property?
you mean, as I am seeing below, to use the "any()" operator produced by a
relationship...
> Here's some sample code to illustrate what I want to
> achieve:
>
> players = relation('Player', back_populates='team')
>
> # This doesn't work
> #has_star_player = column_property(players.any(star=True))
>
> # This works
> has_star_player = column_property(
> exists().where(id == Player.team_id).where(Player.star ==
> True))
>
> # This also works
> Team.__mapper__.add_property(
> 'has_star_player2',
> column_property(Team.players.any(star=True)),
> )
so that's your answer - the two approaches you have are fine. For the other
one, you'd call players.comparator.any(), but that also doesn't work since the
relationship is not aware of its parent mapper at that point.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.