Thanks for response. How do you delete the joined table object of ProjApp.
A direct delete won't do:
mydb.session.delete(projApp)
mydb.session.commit()
the following error arises:
"sqlalchemy.exc.ProgrammingError: (ProgrammingError) relation "APPLICATION"
does not exist
LINE 2: FROM "APPLICATION" JOIN "PROJECT_APP" ON "APPLICATION".app_i..."
I tried google and look at the official documentation
http://docs.sqlalchemy.org/en/rel_1_0/orm/inheritance.html#eager-loading-of-specific-or-polymorphic-subtypes
there weren't any information on that.

On Mon, Jun 22, 2015 at 4:33 AM, Mike Bayer <[email protected]>
wrote:

>
>
> On 6/21/15 1:46 PM, Kevin Qiu wrote:
>
> It's a test db, there's only one record being added to the table. And I
> ensure that with a assertIn() test and it passes.
> The original code was:
>  class Application(mydb.Model):
>  __tablename__ = 'APPLICATION'
>  app_id = mydb.Column(mydb.Integer, primary_key = True)#app_id =
> mydb.Column(mydb.String(30), primary_key = True)
>  created_datetime = mydb.Column(mydb.DateTime(), primary_key = True)
>
>
>  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)
>  c_supervisor = mydb.Column(mydb.String(62),
> mydb.ForeignKey('C_SUPERVISOR.c_sup_email'))
>
>
>  def create_new_internship_app(self, student):
>  internship_app = ProjectApp(
>  app_id=None,
>  created_datetime=datetime.date.today(),
>
>
> you are assigning a Date object to a DateTime column which is critically
> part of the primary key.   The row that comes back therefore has a
> different primary key since date(Y, m, d) != datetime(Y, m, d, 0, 0, 0):
>
> >>> import datetime
> >>> d1 = datetime.date(2015, 5, 10)
> >>> d2 = datetime.datetime(2015, 5, 10, 0, 0, 0)
> >>> d1 == d2
> False
> >>> d1 == d2.date()
> True
>
> I'd try to avoid using dates/datetimes as parts of primary keys because
> they are difficult to equate to each other, for this reason as well as
> issues like microseconds present / non-present, etc.
>
> sample instance keys:
>
> (<class '__main__.ProjectApp'>, (2, datetime.date(2015, 6, 21)))
>
> (<class '__main__.ProjectApp'>, (2, datetime.datetime(2015, 6, 21, 0, 0)))
>
>
>
>
>
>   #deadline_datetime=datetime.date.today() +
> datetime.timedelta(days=PROCESS_TIMEFRAME[CASE_PRIORITY['Project app']]),
>  c_supervisor=None,
>  u_supervisor=None,
>  proj_module=None,
>  proj_title='Internship',
>  proj_description='It\'s long story',
>  proj_salary='No salary',
>  proj_contract=None,
>  proj_insurance=None,
>  proj_s_date=datetime.date(2014,2,1),
>  proj_e_date=datetime.date(2014,5,30),
>  proj_h_date=datetime.date(2014,6,1),
>  #std_comment=None,
>  #std_document=None
>  )
>  mydb.session.add(internship_app)
>  mydb.session.commit()
>  internship_app_rst = mydb.session.query(ProjectApp).one()
>  self.assertIs(internship_app_rst, internship_app)
>  self.assertEquals(internship_app_rst.proj_s_date ,
> internship_app.proj_s_date)
>                 return internship_app
>  On Sunday, June 21, 2015 at 7:20:04 PM UTC+2, Michael Bayer wrote:
>>
>>  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 [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/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 [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/d/optout.
>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "sqlalchemy" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/sqlalchemy/ggKUdxcvVog/unsubscribe.
> To unsubscribe from this group and all its topics, 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/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 [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/d/optout.

Reply via email to