I have two tables Users and Organization.
I have the following SQL mapped classes:
class User(db.Model):
__tablename__ = 'user'
id = db.Column('id', db.Integer, primary_key=True)
first_name = db.Column('first_name', db.String)
second_name = db.Column('second_name', db.String)
last_name = db.Column('last_name', db.String)
# organization_id = db.Column('organization_id', db.Integer)
organization_id = db.Column('organization_id',db.Integer,db.ForeignKey('organization.id'),nullable=False)
# organization = db.relationship('Organization',backref='user',lazy=False)
email = db.Column('email', db.String)
mobile_no = db.Column('mobile_no', db.String)
designation = db.Column('designation', db.String)
role_id = db.Column('role_id', db.Integer)
password = db.Column('password', db.String)
class Organization(db.Model):
__tablename__ = 'organization'
id = db.Column('id',db.Integer,primary_key=True)
name = db.Column('name',db.String)
type_id = db.Column('type_id',db.Integer)
ward_id = db.Column('ward_id',db.Integer)
attrs = ['id','name','type_id','ward_id']
user_organization = db.relationship('User',backref='organization',lazy=False)
I want to perform a join operation on User.onrganization_id and Organization.id with the results looking like this
user.id | user.first_name organization.name | user.email | user.mobile_no
I tried this code:
q = db.session.query(User,Organization).join(Organization).all()
This give me a result as list with collection of object:
[(<User 2>, <Organization 1>)]
I want the return type to be a list of single object and not a collection of objects. Like this
[(<UsersAndOrganization1>)] //Name of the object doesn't have to be the same