On 10/01/2013 23:52, Michael Bayer wrote:
On Jan 10, 2013, at 3:35 AM, Chris Withers wrote:
Hi All,
If I have an unmapped object which has had some attributes set on it, what
would be the best way to use that object to load a mapped object?
I didn't noticed a session.lookup(myobj) method ;-)
what is it looking up ? what's a "myobj" ?
An unmapped instance of the mapped class.
Here's a unit test I'd like to have pass, although in this example
lookup is implemented as a method on the mapped class:
class LookupTests(TestCase):
def setUp(self):
Base = declarative_base()
class Model(Common, Base):
id = Column(Integer, primary_key=True)
value1 = Column(Integer, nullable=False)
value2 = Column(Integer, default=42)
self.Model = Model
registerSession(metadata=Base.metadata)
def test_simple(self):
session = getSession()
model1 = session.add(self.Model(id=1, value1=2, value2=3))
model2 = Model(value1=2).lookup(session)
self.assertTrue(model2 is model1)
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.