sqlalchemy自我引用关系,不包括\'self\'

问题描述

| 我有一个简单的数据结构,其中电影表具有国家表的外键。 为了检索来自同一国家的所有电影,我具有此属性'same_country_films \',这是一种自指关系。 它几乎可以正确地完成工作,但是,它也将电影本身包括在列表中。如何排除其他电影? 非常感谢!
from sqlalchemy import Table,Column,Integer,String,MetaData,ForeignKey 
from sqlalchemy.orm import mapper,relationship
metadata = MetaData()
country_table = Table(\'country\',metadata,Column(\'id\',primary_key=True),Column(\'name\',String),)
film_table = Table(\'film\',Column(\'title\',Column(\'year\',Integer),Column(\'country_id\',ForeignKey(\'country.id\'))
    )

class Country(object):
    pass

class Film(object):
    pass

mapper(Country,country_table)

mapper(Film,film_table,properties={
            \'country\':relationship(
                    Country,backref=\'films\'),\'same_country_films\':relationship(
                    Film,primaryjoin=film_table.c.country_id==\\
                                film_table.c.country_id,foreign_keys=[
                        film_table.c.country_id,]
                    )
             }
    )
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)