python - Flask SQLalchemy order_by value joined from two Tables -


currently cant figure out how perform proper join in sqlalchemy, have 2 tables user , roomeach room submited user , why each room has users_id foreign key.

user has attribute has_payed.

what want query rooms in city (works fine) , order these results user.has_payed value. shall show first rooms belong users have has_payed == true.

what doing:

room.query.join(room.users_id).order_by(user.has_payed) 

that tables:

class user(usermixin, base):     __tablename__ = 'users'     id = column(integer, primary_key=true)     username = column(text, nullable=false, unique=true)     password = column(text, nullable=false)     has_payed = column(boolean, default=false)     vorname = column(text, nullable=true)     nachname = column(text, nullable=true)     email_verified = column(boolean, default=false)     handynummer = column(text, nullable=true)     email = column(text, unique=true)     # foreign key     addresses = relationship('room', back_populates="users")    class room(base):     __tablename__ = 'zimmer'     id = column(integer, primary_key=true)     art = column(text, nullable=false)     personen = column(integer, nullable=false)     preis = column(integer, nullable=false)     infofeld = column(text, nullable=false)     land = column(text, nullable=false)     bundesland = column(text, nullable=false)     stadt = column(text, nullable=false)     plz = column(text, nullable=false)     strasse = column(text, nullable=false)     hausnr = column(text, nullable=true)     zimmer_lat = column(float, nullable=false)     zimmer_lng = column(float, nullable=false)      # foreign key     users_id = column(integer, foreignkey('users.id'))     users = relationship("user", back_populates="addresses") 

it seems solved issue, dont know how knows has join on room.users_id == user.id

room.query.join(user).order_by(desc(user.has_payed)) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -