SQL炼金术:具有关系的类似VersionedHistory的类

时间:2019-06-24 11:45:27

标签: python sqlalchemy

我通过将<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> </head> <body> <input type='file' onchange="readURL(this);" /> <img id="blah" src="#" alt="your image" /> </body> <script type="text/javascript"> function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $('#blah') .attr('src', e.target.result) .width(260) .height(100); }; reader.readAsDataURL(input.files[0]); } } </script> 添加到带有VerionedHistory example的类来扩展relationship。创建这两个类之一的实例时,也可以访问另一个类的实例。

问题是当我想使用过滤器时。父母/孩子的属性尚不可用。

backref

以上查询将因错误而失败:

local_mapper.add_property(
    'changes_',
    relationship(
        versioned_cls,
        primaryjoin=foreign(versioned_cls.entity).like(cls.id + '%%'),
        backref='entity_instance',
    ),
)

# later on in main app code...
db.session.query(change_class).filter(change_class.entity_instance.name.like('DUMMY%')).all()

父级从类似AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with FeatureChange.entity_instance has an attribute 'name' 的类继承,就像示例中的VerionedHistory

Pastebin,其中包含我的类似VersionHistory的父类的详细实现。

如何强制SQL Alchemy做到“神奇”并交换这两个父子表的列?

[EDIT 2019-06-25]:不重复

作为我的问题的答案提供的问题正在解决相似但不是相同的问题。我无法从对应类访问class Parent(Versioned, Base)child类的列。这使我无法根据需要应用过滤器和联接(将不得不再次联接它们,但这有点奇怪-在定义了关系后为什么要联接它们?)。

P.S。我确实发现parent也适用于整个班级。以下作品:

has

但是我仍然不能使用基于父级列的联接或访问父级的其他子级/子级。

0 个答案:

没有答案