lazyload, aliased
from test.lib import fixtures
from test.orm import _fixtures
-from test.lib.pickleable import User, Address, Order, Child1, Child2, Parent, Screen, EmailUser
+from test.lib.pickleable import User, Address, Dingaling, Order, \
+ Child1, Child2, Parent, Screen, EmailUser
class PickleTest(fixtures.MappedTest):
test_needs_acid=True,
test_needs_fk=True
)
+ Table("dingalings", metadata,
+ Column('id', Integer, primary_key=True, test_needs_autoincrement=True),
+ Column('address_id', None, ForeignKey('addresses.id')),
+ Column('data', String(30)),
+ test_needs_acid=True,
+ test_needs_fk=True
+ )
def test_transient(self):
def test_options_with_descriptors(self):
- users, addresses = (self.tables.users,
- self.tables.addresses)
+ users, addresses, dingalings = (self.tables.users,
+ self.tables.addresses,
+ self.tables.dingalings)
mapper(User, users, properties={
'addresses':relationship(Address, backref="user")
})
- mapper(Address, addresses)
+ mapper(Address, addresses, properties={
+ 'dingaling':relationship(Dingaling)
+ })
+ mapper(Dingaling, dingalings)
sess = create_session()
u1 = User(name='ed')
u1.addresses.append(Address(email_address='ed@bar.com'))
sa.orm.joinedload("addresses"),
sa.orm.defer("name"),
sa.orm.defer(User.name),
- sa.orm.joinedload("addresses", User.addresses),
+ sa.orm.joinedload("addresses", Address.dingaling),
]:
opt2 = pickle.loads(pickle.dumps(opt))
eq_(opt.key, opt2.key)
u1 = sess.query(User).options(opt).first()
-
u2 = pickle.loads(pickle.dumps(u1))
def test_collection_setstate(self):
def test_option_against_nonexistent_PropComparator(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword],
(joinedload(Item.keywords), ),
r"Can't find property 'keywords' on any entity specified "
def test_option_against_nonexistent_basestring(self):
Item = self.classes.Item
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Item],
(joinedload("foo"), ),
r"Can't find property named 'foo' on the mapped "
def test_option_against_nonexistent_twolevel_basestring(self):
Item = self.classes.Item
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Item],
(joinedload("keywords.foo"), ),
r"Can't find property named 'foo' on the mapped entity "
def test_option_against_nonexistent_twolevel_all(self):
Item = self.classes.Item
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Item],
(joinedload_all("keywords.foo"), ),
r"Can't find property named 'foo' on the mapped entity "
def test_option_against_non_relation_basestring(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword, Item],
(joinedload_all("keywords"), ),
r"Attribute 'keywords' of entity 'Mapper\|Keyword\|keywords' "
def test_option_against_multi_non_relation_basestring(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword, Item],
(joinedload_all("keywords"), ),
r"Attribute 'keywords' of entity 'Mapper\|Keyword\|keywords' "
def test_option_against_wrong_entity_type_basestring(self):
Item = self.classes.Item
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Item],
(joinedload_all("id", "keywords"), ),
r"Attribute 'id' of entity 'Mapper\|Item\|items' does not "
def test_option_against_multi_non_relation_twolevel_basestring(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword, Item],
(joinedload_all("id", "keywords"), ),
r"Attribute 'id' of entity 'Mapper\|Keyword\|keywords' "
def test_option_against_multi_nonexistent_basestring(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword, Item],
(joinedload_all("description"), ),
r"Can't find property named 'description' on the mapped "
def test_option_against_multi_no_entities_basestring(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword.id, Item.id],
(joinedload_all("keywords"), ),
r"Query has only expression-based entities - can't find property "
def test_option_against_wrong_multi_entity_type_attr_one(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword, Item],
(joinedload_all(Keyword.id, Item.keywords), ),
r"Attribute 'Keyword.id' of entity 'Mapper\|Keyword\|keywords' "
def test_option_against_wrong_multi_entity_type_attr_two(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword, Item],
(joinedload_all(Keyword.keywords, Item.keywords), ),
r"Attribute 'Keyword.keywords' of entity 'Mapper\|Keyword\|keywords' "
def test_option_against_wrong_multi_entity_type_attr_three(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Keyword.id, Item.id],
(joinedload_all(Keyword.keywords, Item.keywords), ),
r"Query has only expression-based entities - "
def test_wrong_type_in_option(self):
Item = self.classes.Item
Keyword = self.classes.Keyword
- self._assert_eager_not_found_exception(
+ self._assert_eager_with_entity_exception(
[Item],
(joinedload_all(Keyword), ),
r"mapper option expects string key or list of attributes"
)
+ def test_non_contiguous_all_option(self):
+ User = self.classes.User
+ self._assert_eager_with_entity_exception(
+ [User],
+ (joinedload_all(User.addresses, User.orders), ),
+ r"Attribute 'User.orders' does not link "
+ "from element 'Mapper|Address|addresses'"
+ )
+
@classmethod
def setup_mappers(cls):
+ users, User, addresses, Address, orders, Order = (
+ cls.tables.users, cls.classes.User,
+ cls.tables.addresses, cls.classes.Address,
+ cls.tables.orders, cls.classes.Order)
+ mapper(User, users, properties={
+ 'addresses':relationship(Address),
+ 'orders':relationship(Order)
+ })
+ mapper(Address, addresses)
+ mapper(Order, orders)
keywords, items, item_keywords, Keyword, Item = (cls.tables.keywords,
cls.tables.items,
cls.tables.item_keywords,
key = ('loaderstrategy', (class_mapper(Item), 'keywords'))
assert key in q._attributes
- def _assert_eager_not_found_exception(self, entity_list, options,
+ def _assert_eager_with_entity_exception(self, entity_list, options,
message):
assert_raises_message(sa.exc.ArgumentError,
message,