This is my model, Players and Clubs. As a Club can have many players and a player can have many clubs (in its carrer), I used a many-to-many relationship:
class Club(db.Model):
name = db.StringProperty()
link = db.StringProperty()
class Player(db.Model):
name = db.StringProperty()
link = db.LinkProperty()
class ClubHasPlayer(db.Model):
club = db.ReferenceProperty(Club, required=True,
collection_name='club_players')
player = db.ReferenceProperty(Player, required=True,
collection_name='player_clubs')
number = IntegerProperty()
Now, I have a search interface where one can search for all players, and add zero or more restrictions, such as player name, and club where he played. Thus, I have a cascade type of handling this:
players = player.all()
if filter_by_player_name:
players.filter("name =",filter_by_player_name)
Now, I want to do this:
if filter_by_club_name:
players.filter(????)
I still think in terms of SQL, and it should be something like a nested clause :
select * from player where player.name='x' and player.id in (select club_has_player.player_id from club_has_player, club where club_has_player.club_id = club.id and club_name = "Y")
How to do it?
I know I could go from the club, that is:
club = Club.filter("name =",filter_by_club_name).get() club.club_players
but this style discards a previous filter, that could be player names...
Can anybody help me here? Thanks.