나는 Elixir에서 sqlalchemy를 사용하고 있으며 쿼리를 만들려고 몇 가지 어려움을 겪고 있습니다.Sqlalchemy + elixir : ManyToMany 관계로 쿼리하는 방법?
대다수의 관계가있는 Customer와 CustomerList라는 두 개의 엔터티가 있습니다.
global name 'customers' is not defined
고객이 엔티티 필드와 관련이없는 것 같다 :
customer_lists_customers_table = Table('customer_lists_customers',
metadata,
Column('id', Integer, primary_key=True),
Column('customer_list_id', Integer, ForeignKey("customer_lists.id")),
Column('customer_id', Integer, ForeignKey("customers.id")))
class Customer(Entity):
[...]
customer_lists = ManyToMany('CustomerList', table=customer_lists_customers_table)
class CustomerList(Entity):
[...]
customers = ManyToMany('Customer', table=customer_lists_customers_table)
나는 어떤 고객과하여 customerList을 찾기 위해 tryng 해요 :
customer = [...]
CustomerList.query.filter_by(customers.contains(customer)).all()
하지만 오류를 얻을 : 나가서 설명하자면 NameError를 , 관계 (또는 ManyToMany 관계)와 함께 작동하는 특별한 쿼리 양식이 있습니까?
감사합니다.
물론입니다. 나는 그것을 이해하지만 왜 그런 일이 일어나는가? 다른 모든 경우에는 엔터티가없는 필드를 사용할 수 있습니다. – Hugo