Removed hybrid expression from eav property generator
This commit is contained in:
@@ -218,18 +218,12 @@ def instrument_meta_values(mapper, class_):
|
|||||||
value
|
value
|
||||||
)
|
)
|
||||||
|
|
||||||
def expression(self):
|
|
||||||
return sa.func.coalesce(
|
|
||||||
*map(lambda key: getattr(self, key), generated_keys)
|
|
||||||
)
|
|
||||||
|
|
||||||
operations.append((
|
operations.append((
|
||||||
class_,
|
class_,
|
||||||
key,
|
key,
|
||||||
hybrid_property(
|
property(
|
||||||
getter,
|
getter,
|
||||||
setter,
|
setter
|
||||||
expr=expression
|
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@@ -55,13 +55,7 @@ class TestMetaModel(TestCase):
|
|||||||
question = self.Question(data_type=sa.String)
|
question = self.Question(data_type=sa.String)
|
||||||
answer = self.Answer(question=question)
|
answer = self.Answer(question=question)
|
||||||
answer.value = 'some answer'
|
answer.value = 'some answer'
|
||||||
assert answer.value == answer.value_str
|
assert answer.value == answer.value_str == 'some answer'
|
||||||
|
|
||||||
def test_meta_value_as_expression(self):
|
|
||||||
assert str(self.Answer.value) == (
|
|
||||||
'coalesce(answer.value_int, answer.value_unicode'
|
|
||||||
', answer.value_str, answer.value_datetime)'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class MetaTypedCollection(MappedCollection):
|
class MetaTypedCollection(MappedCollection):
|
||||||
@@ -280,24 +274,24 @@ class TestProductCatalog(TestCase):
|
|||||||
assert product.attributes[u'color'] == u'red'
|
assert product.attributes[u'color'] == u'red'
|
||||||
assert product.attributes[u'maxspeed'] == 300
|
assert product.attributes[u'maxspeed'] == 300
|
||||||
|
|
||||||
def test_dynamic_hybrid_properties(self):
|
# def test_dynamic_hybrid_properties(self):
|
||||||
category = self.Category(name=u'cars')
|
# category = self.Category(name=u'cars')
|
||||||
category.attributes = {
|
# category.attributes = {
|
||||||
u'color': self.Attribute(name=u'color', data_type=sa.UnicodeText),
|
# u'color': self.Attribute(name=u'color', data_type=sa.UnicodeText),
|
||||||
u'maxspeed': self.Attribute(name=u'maxspeed', data_type=sa.Integer)
|
# u'maxspeed': self.Attribute(name=u'maxspeed', data_type=sa.Integer)
|
||||||
}
|
# }
|
||||||
product = self.Product(
|
# product = self.Product(
|
||||||
name=u'Porsche 911',
|
# name=u'Porsche 911',
|
||||||
category=category
|
# category=category
|
||||||
)
|
# )
|
||||||
self.session.add(product)
|
# self.session.add(product)
|
||||||
|
|
||||||
product.attributes[u'color'] = u'red'
|
# product.attributes[u'color'] = u'red'
|
||||||
product.attributes[u'maxspeed'] = 300
|
# product.attributes[u'maxspeed'] = 300
|
||||||
self.session.commit()
|
# self.session.commit()
|
||||||
|
|
||||||
(
|
# (
|
||||||
self.session.query(self.Product)
|
# self.session.query(self.Product)
|
||||||
.filter(self.Product.attributes['color'].in_([u'red', u'blue']))
|
# .filter(self.Product.attributes['color'].in_([u'red', u'blue']))
|
||||||
.order_by(self.Product.attributes['color'])
|
# .order_by(self.Product.attributes['color'])
|
||||||
)
|
# )
|
||||||
|
Reference in New Issue
Block a user