Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
Obtenga la intersección de objetos ORM en SQLAlchemy

Tengo los siguientes modelos:

 class User(db.Model): ... #One user can have many roles, many roles can be on many users roles = db.relationship('Role', secondary='users_roles', backref=db.backref('users', lazy='dynamic') class Role(db.Model): id = .. name = .. class Notification(db.Model): ... user_id = db.Column(db.Integer, db.ForeignKey('users.id')) #a notification can be shown for several roles shows_for = db.relationship('Role', secondary='notifications_roles', backref=db.backref('user_notifications', lazy='dynamic'))

Y estoy tratando de crear una consulta para obtener todas las notificaciones de un usuario, dadas sus funciones:

 def get_notifications(): #Get the current user's roles: usr_roles = db.session.query(User).filter_by(id=current_user.id).first().roles #Get notifications to show for that user relevant_notifications = (Notification.query.filter( Notification.shows_for_roles.in_(usr_roles)).all()

Ahora, esto no funciona ( NotImplementedError: in_() not yet supported for relationships. For a simple many-to-one, use in_() against the set of foreign key values.

¿Cómo haría para obtener los objetos que tienen uno o más roles vinculados a ellos que también están en mi objeto Usuario?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!