From 23652c79c7da83823aa431482d2c61708d6060f6 Mon Sep 17 00:00:00 2001 From: Konsta Vesterinen Date: Fri, 15 Nov 2013 11:18:23 +0200 Subject: [PATCH] Removed hybrid expression from eav property generator --- sqlalchemy_utils/eav.py | 10 ++------- tests/test_eav.py | 46 ++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 34 deletions(-) diff --git a/sqlalchemy_utils/eav.py b/sqlalchemy_utils/eav.py index 13def17..5d9c867 100644 --- a/sqlalchemy_utils/eav.py +++ b/sqlalchemy_utils/eav.py @@ -218,18 +218,12 @@ def instrument_meta_values(mapper, class_): value ) - def expression(self): - return sa.func.coalesce( - *map(lambda key: getattr(self, key), generated_keys) - ) - operations.append(( class_, key, - hybrid_property( + property( getter, - setter, - expr=expression + setter ) )) diff --git a/tests/test_eav.py b/tests/test_eav.py index 7e55121..b38a762 100644 --- a/tests/test_eav.py +++ b/tests/test_eav.py @@ -55,13 +55,7 @@ class TestMetaModel(TestCase): question = self.Question(data_type=sa.String) answer = self.Answer(question=question) answer.value = 'some answer' - assert answer.value == answer.value_str - - 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)' - ) + assert answer.value == answer.value_str == 'some answer' class MetaTypedCollection(MappedCollection): @@ -280,24 +274,24 @@ class TestProductCatalog(TestCase): assert product.attributes[u'color'] == u'red' assert product.attributes[u'maxspeed'] == 300 - def test_dynamic_hybrid_properties(self): - category = self.Category(name=u'cars') - category.attributes = { - u'color': self.Attribute(name=u'color', data_type=sa.UnicodeText), - u'maxspeed': self.Attribute(name=u'maxspeed', data_type=sa.Integer) - } - product = self.Product( - name=u'Porsche 911', - category=category - ) - self.session.add(product) + # def test_dynamic_hybrid_properties(self): + # category = self.Category(name=u'cars') + # category.attributes = { + # u'color': self.Attribute(name=u'color', data_type=sa.UnicodeText), + # u'maxspeed': self.Attribute(name=u'maxspeed', data_type=sa.Integer) + # } + # product = self.Product( + # name=u'Porsche 911', + # category=category + # ) + # self.session.add(product) - product.attributes[u'color'] = u'red' - product.attributes[u'maxspeed'] = 300 - self.session.commit() + # product.attributes[u'color'] = u'red' + # product.attributes[u'maxspeed'] = 300 + # self.session.commit() - ( - self.session.query(self.Product) - .filter(self.Product.attributes['color'].in_([u'red', u'blue'])) - .order_by(self.Product.attributes['color']) - ) + # ( + # self.session.query(self.Product) + # .filter(self.Product.attributes['color'].in_([u'red', u'blue'])) + # .order_by(self.Product.attributes['color']) + # )