did you try adding an ORDER BY to that query? calling query.first()
will return only the first result in an unordered list. It is
essentially random.
On 6/21/15 12:45 PM, Kevin Qiu wrote:
I create a unit test that add new ProjApp object to the database, but
the returned object shows it is not the same object inserted, I don't
follow why it's like this because I have others tests on inserting a
row to a different table, and returned shows the same row object.
Test result:
self.assertIs(internship_app_rst, internship_app)
AssertionError: <project.models.ProjectApp object at
0x0000000003EE7E10> is not <project.models.ProjectApp object at 0x0
000000003EE7710>
Test:
def create_new_internship_app(self, student):
internship_app = ProjectApp(
app_id=None,
created_datetime=datetime.date.today(),
proj_title='Long story'
)
mydb.session.add(internship_app)
mydb.session.commit()
internship_app_rst = mydb.session.query(ProjectApp).first()
self.assertIs(internship_app_rst, internship_app)
Model:
class Application(mydb.Model):
__tablename__ = 'APPLICATION'
app_id = mydb.Column(mydb.Integer, primary_key = True)
created_datetime = mydb.Column(mydb.DateTime(), primary_key = True)
app_description = mydb.Column(mydb.Text())
app_category = mydb.Column(mydb.String(30))
case_owner_obj = mydb.relationship('Staff', backref='application_list')
__mapper_args__ = {
'polymorphic_identity':'application',
'polymorphic_on':app_category
}
class ProjectApp(Application):
__tablename__ = 'PROJECT_APP'
__table_args__ = (
mydb.ForeignKeyConstraint(
['app_id','created_datetime'],
['APPLICATION.app_id', 'APPLICATION.created_datetime']
),
)
app_id = mydb.Column(mydb.Integer, primary_key = True)
created_datetime = mydb.Column(mydb.DateTime(), primary_key = True)
proj_title = mydb.Column(mydb.Text())
__mapper_args__ = {
'polymorphic_identity':'projApp',
}
--
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 sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.