Digging up an old thread, this time with (I hope) correct terminology:
If I have a transient object which has had some attributes set on it,
what would be the best way to use that object to load an object based on
those attributes from the database?
I didn't noticed a session.lookup(myobj) method ;-)
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
register_session(metadata=Base.metadata)
def test_simple(self):
session = get_session()
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.