-2
\$\begingroup\$

which way is better :

1st way : I want to get owner data of every device one by one . so need to call database again and again for every device like this

      for room in rooms:
          owner = session.query(Owner).filter(device_id =device.id)
            room_data = {
                "Id": room.room_uuid,
                "owner" : owner.name 
            }
            array.append(room_data)

or 2nd way :

first query for all data of owner table: owner = session.query(Owner).all()

 for room in rooms:
           then iterate here  `owner` objects to find owner 
            room_data = {
                "Id": room.room_uuid,
                "owner" : owner.name 
            }
            array.append(room_data)

P.s I tried to create a dummy scenario so kindly ignore any other issue please

New contributor
newbir is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
2