0

I have a user object:

class User():
    id = Column(Integer, primary_key=True)
    name = Column(String(255), unique=True, nullable=False)
    active = Column(Boolean())
    user_domain_id = Column(Integer, ForeignKey("domain_info.domain_id"))
    user_domain = relationship('DomainInfo',  foreign_keys=[user_domain_id])

And I am trying to add a user_domain to a set of users by using a listener:

@event.listens_for(DomainInfo, "after_insert")
def after_domain_insert(mapper, connection, target):
    user_domain = DomainInfo.query.filter(func.lower(DomainInfo.domain_name) == func.lower("some_criteria").first()
    stmt = user_tables.update().\
        values(active=True, user_domain=target). \
        where(func.lower(User.email).like('%' + func.lower(target.domain_name)))
    connection.execute(stmt)

I get the following error:

sqlalchemy.exc.CompileError
sqlalchemy.exc.CompileError: Unconsumed column names: user_domain

What is the best way to update the user objects while using a connection ?

39fredy
  • 1,923
  • 2
  • 21
  • 40

1 Answers1

0

I figured it out by updating the user_domain_id with target.domain_id instead of updating the user_domain with target

stmt = user_tables.update().\
        values(active=True, user_domain_id=target.domain_id). \
        where(func.lower(User.email).like('%' + func.lower(target.domain_name)))
connection.execute(stmt)
39fredy
  • 1,923
  • 2
  • 21
  • 40