def object_mapper(object):
"""given an object, returns the primary Mapper associated with the object
or the object's class."""
- try:
- return _mappers[object._mapper]
- except AttributeError:
- return class_mapper(object.__class__)
+ return class_mapper(object.__class__)
+# try:
+# return _mappers[object._mapper]
+# except AttributeError:
+# return class_mapper(object.__class__)
def class_mapper(class_):
"""given a class, returns the primary Mapper associated with the class."""
instance = self.extension.create_instance(self, row, imap, self.class_)
if instance is None:
instance = self.class_(_mapper_nohistory=True)
- instance._mapper = self.hashkey
+ # attach mapper hashkey to the instance ?
+ #instance._mapper = self.hashkey
instance._instance_key = identitykey
imap[identitykey] = instance
return (obj2, obj1)
def process_dependencies(self, task, deplist, uowcommit, delete = False):
- #print self.mapper.table.name + " " + repr(len(deplist)) + " process_dep isdelete " + repr(delete)
+ print self.mapper.table.name + " " + repr(len(deplist)) + " process_dep isdelete " + repr(delete)
# fucntion to set properties across a parent/child object plus an "association row",
# based on a join condition
self.assert_(addresstable[0].row == (addressid, userid, 'somethingnew@foo.com'))
self.assert_(u.user_id == userid and a2.address_id == addressid)
- def testonetomany2(self):
+ def testmapperswitch(self):
+ """test that, if we change mappers, the new one gets used fully. not sure if
+ i want it to work that way, but probably."""
users.insert().execute(
dict(user_id = 7, user_name = 'jack'),
dict(user_id = 8, user_name = 'ed'),
dict(user_id = 9, user_name = 'fred')
)
db.connection().commit()
+
+ User.mapper = assignmapper(users)
+ User.mapper.select()
User.mapper = assignmapper(users, properties = dict(
addresses = relation(Address, addresses, lazy = False)
))
u = User.mapper.select()
u[0].addresses.append(Address())
u[0].addresses[0].email_address='hi'
- objectstore.commit()
+ self.assert_sql(db, lambda: objectstore.commit(),
+ [
+ (
+ "INSERT INTO email_addresses (address_id, user_id, email_address) VALUES (:address_id, :user_id, :email_address)",
+ {'email_address': 'hi', 'address_id': None, 'user_id': 7}
+ ),
+ ]
+ )
def testchildmanipulations(self):
"""digs deeper into modifying the child items of an object to insure the correct
(query, params) = item
if callable(params):
params = params()
- self.unittest.assert_(statement == query and params == parameters, query + repr(params) + statement + repr(parameters))
+ self.unittest.assert_(statement == query and params == parameters, "Testing for query '%s' params %s, received '%s' with params %s" % (query, repr(params), statement, repr(parameters)))
return self.realexec(statement, parameters, **kwargs)
def runTests(suite):