Hi
Is there a way to compare mapped objects by values and not by identity? I
want to create an instance of some mapped class, set its attributes
(including relationship one to many) to some values and then ask SQLAlchemy
to check if there is such object in database.
Let me explain wider context of what I am trying to do. I am writing
component test for my application. The test should create a set of data,
save the data in .csv file, make application read the file and then verify
that proper records were inserted into database. So I was going to use
classes that are mapped to database as my model, create some objects, set
their attributes, create .csv file based on these objects and then use the
objects to check if data was properly stored in database.
A more precise example. Let's assume we have two classes:
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
fullname = Column(String)
password = Column(String)
addresses = relationship("Address", order_by="Address.id",
backref="user")
class Address(Base):
__tablename__ = 'addresses'
id = Column(Integer, primary_key=True)
email_address = Column(String, nullable=False)
user_id = Column(Integer, ForeignKey('users.id'))
I want to create instance of User, set its name, fullname, password and add
a few addresses. Now I want to query database for object with exactly the
same properties including same addresses. How can I do it? Is it possible
to avoid explicit comparisons of each field?
Regards
Marcin
--
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.