Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Peer::doDelete() fails when using inheritance

propel
Discussion topic

Back to topic list

Peer::doDelete() fails when using inheritance

Reply

Author noel guilbert <noelguilbert at gmail dot com>
Full name noel guilbert <noelguilbert at gmail dot com>
Date 2008-05-07 06:43:37 PDT
Message Hello,

I wanted to post this bug report in Trac, but it gets rejected as spam. So
I hope someone could post this bug report for me ;)

I'm using Propel with the symfony framework, and I'm annoyed with a bug when
I'm using inheritance.

Here is my schema.xml:

{{{
<?xml version="1.0" encoding="UTF-8"?>
<database package="lib.model.mail" name="propel" defaultIdMethod="native"
noxsd="true">

  <table name="mail_template" phpName="MailTemplate" isI18N="true"
i18nTable="mail_temp​late_i18n">
    <column name="id" type="integer" required="true" primaryKey="true"
autoIncrement="true"/>
    <column name="status" type="char" size="3" required="true"/>
    <column name="plugin" type="integer" required="true"/>
    <column name="class_key" type="integer" inheritance="single">
      <inheritance key="1" class="AdminMailTemplate"/>
      <inheritance key="2" class="AffiliateMail​Template"/>
      <inheritance key="3" class="CustomerMailT​emplate"/>
    </column>
  </table>

  <table name="mail_template_i18n">
    <column name="id" type="integer" required="true" primaryKey="true"/>
    <column name="culture" type="varchar" size="7" required="true"
primaryKey="true" isCulture="true"/>
    <column name="subject" type="varchar" size="256"/>
    <column name="body" type="longvarchar"/>
    <column name="alternative_body" type="longvarchar"/>

    <foreign-key foreignTable="mail_t​emplate">
      <reference local="id" foreign="id" onDelete="CASCADE"/>
    </foreign-key>
  </table>
</database>

}}}

And here is my code:
{{{
$mailTemplate = new MailTemplate();
    $mailTemplate->setStatus(1);
    $mailTemplate->setPlugin(1);
    $mailTemplate->s​etCulture('fr');
    $mailTemplate->s​etSubject('test');
    $mailTemplate->s​etBody('test');
    $mailTemplate->s​etClassKey(1);

    $mailTemplate->save();

    // Deleting the object
    $mailTemplate->delete();
}}}

My problem comes from the delete query, which is:

{{{
DELETE FROM mail_template WHERE mail_template.ID IN
(14,1,1,1,NULL,NULL,​0,0,NULL,0,0,0,0,0)
}}}

As you can see, the query is performing a delete on a set of ids, instead of
the object id (14). The problem comes from the doDelete() method, which is
testing the object type before delete. In my case, $values is an
"AdminMailTemplate" object, which extends BaseMailTemplate, so it does a
"Criteria::IN":

{{{
public static function doDelete($values, $con = null)
{
  if ($con === null) {
    $con = Propel::getConnectio​n(MailTemplatePeer::​DATABASE_NAME);
  }

  if ($values instanceof Criteria) {
    $criteria = clone $values;
  } elseif ($values instanceof MailTemplate) { // Should do this
case

    $criteria = $values->buildPk​eyCriteria();
  } else { // But does this
one
    $criteria = new Criteria(self::DATABASE_NAME);
    $criteria->add(M​ailTemplatePeer::ID,​ (array) $values, Criteria::IN);
  }
}}}


I don't know what should be the best solution to fix this bug, but we could
change the test of the object type:

{{{
if ($value instanceof MailTemplate)
}}}

by

{{{
if ($value instanceof BaseMailTemplate)
}}}

Thank you!

--
Noël GUILBERT
Attachments

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

Peer::doDelete() fails when using inheritance noel guilbert <noelguilbert at gmail dot com> noel guilbert <noelguilbert at gmail dot com> 2008-05-07 06:43:37 PDT
Messages per page: