Ben Law
Ben Law

Reputation: 58

In web2py, how to find a row from rows given its id?

I have

query= (db.mytable.ref_other_table==other_table_id)
rows=db(query).select()

How can I find a row in rows, knowing the records id, for instance, I can do

ix=0
while rows[ix].id != id:
    ix+=1

but is this the most efficient way?

Upvotes: 0

Views: 678

Answers (1)

Anthony
Anthony

Reputation: 25536

row = rows.find(lambda r: r.id == some_id)

However, depending on how many records are in rows, it could actually be faster to just retrieve the record directly from the database:

row = db.mytable(some_id)

Upvotes: 1

Related Questions