uhm? seems the case for a join (if you are not on GAE)
p = db.providers
g = db.games
pg = db.provider_games
result = db(
(p.key == providerKey) & #make sure you have a valid providerKey
(g.key == gameKey) & #make sure you have a valid gameKey
(pg.providerID == p.id) & #link the providers table to the
providers_game table
(pg.gameID == g.id) #link the games table to the providers_game table
).select().first()
if not result:
return 'trying to fake keys'
else:
return 'good to go'
On Wednesday, November 28, 2012 11:58:34 PM UTC+1, pumplerod wrote:
>
> I'm having trouble finding a clear example of this and I feel like what
> I'm doing is far more complicated than it should be. I'm sure someone in
> this group can show me a more elegant solution...
>
> I have a table of Providers and a table of Games. Each provider can have
> multiple games so I also have a table: providers_games which is just a list
> of providerID and gameID
>
> to validate incoming data a query must have a secret_key for the provider
> and a secret_key for the game. I first find the providerID by looking up
> the provider_secret_key then find the gameID by looking up the
> game_secret_key.
>
> Now I want to check to make sure that there is, indeed, an entry in
> providers_games where providers_games.providerID == foundProviderID and
> provider_games.gameID == foundGameID
>
> I thought some clever use of IS_IN_DB would be my solution but that seems
> to be eluding me.
>
> my sudo-code:
>
> provider, = db(db.providers.key == providerKey).select()
> game, = db(db.games.key == gameKey).select()
> qset = db()
> qset = qset(db.providers_games.providerID == provider.id)
> qset = qset(db.providers_games.gameID == game.id)
> result, = qset.select()
>
> This is pretty ugly. I'm sure there is a better way.
>
--