Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix for lack of "use" statement in BaseQuery subclasses in single table inheritance when using namespaces #774

Open
wants to merge 3 commits into from

3 participants

@noofaq

Fix for lack of "use" statement in BaseQuery subclasses in single table inheritance when using namespaces

Requiements to reproduce problem:

  • we are using namespace for all classes generated by Propel
  • we have Book class which has subclasses Essay & Comic

Problem description:

  • generated BaseEssayQuery class extends BookQuery but it does not have "use" statement for it, so it causes errors when class is used

Solution:

  • call class declaration when parent class name is being guessed (it adds required use statement if it wasn't already defined)
noofaq added some commits
@noofaq noofaq Fix for lack of "use" statement in BaseQuery subclasses in single tab…
…le inheritance when using namespaces

Requiements:
* we are using namespace for all classes generated by Propel
* we have Book class which has subclasses Essay & Comic

Problem:
* generated BaseEssayQuery class extends BookQuery but it does not have "use" statement for it so it causes errors

Solution:
* call class declaration when parent class name is being guessed (it adds required use statement if it wasn't already defined)
7090b7f
@noofaq noofaq 2nd fix for lacking "use" statement - this time for Peer class b19cc0d
generator/lib/builder/om/QueryInheritanceBuilder.php
@@ -133,6 +136,9 @@ protected function addClassOpen(&$script)
$baseBuilder = $this->getStubQueryBuilder();
$this->declareClassFromBuilder($baseBuilder);
$baseClassname = $this->getParentClassName();
+
+ //[noofaq] add peer class declaration to have "use" statement available
@staabm Collaborator
staabm added a note

please remove your nickname

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@staabm
Collaborator

do you see a way to unit/functional-test this somehow?

@noofaq

the only possible test I see: have a DB schema with namespace & inheritance included, than rebuild models (to regenerate Query subclass) and than try to create an instance of this Query subclass (what causes fatal error of non-existent class/classes) - for me it looks like really complex test scenario

@staabm
Collaborator

for me it looks like really complex test scenario

think so too... seems to complex for this simple case.

@marcj
Owner

Nah, the test'd be pretty easy:


    $schema = '
<database name="bookstore" ....>
  <table name="issue774">
    <column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" />
    <column name="name" type="VARCHAR" size="50" required="true" />
    ....
  </table>
</database>
';

    $builder = new PropelQuickBuilder();
    $builder->setPlatform(New MysqlPlatform);
    $builder->setSchema($schema);

    $builder->buildClasses();

   \Issue774Query::create() .....
@staabm
Collaborator

@noofaq would you give this test snippet a try

@marcj thanks man.

@staabm
Collaborator

@noofaq dod you have time to finish things?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 15, 2013
  1. @noofaq

    Fix for lack of "use" statement in BaseQuery subclasses in single tab…

    noofaq authored
    …le inheritance when using namespaces
    
    Requiements:
    * we are using namespace for all classes generated by Propel
    * we have Book class which has subclasses Essay & Comic
    
    Problem:
    * generated BaseEssayQuery class extends BookQuery but it does not have "use" statement for it so it causes errors
    
    Solution:
    * call class declaration when parent class name is being guessed (it adds required use statement if it wasn't already defined)
  2. @noofaq
  3. @noofaq
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 1 deletion.
  1. +7 −1 generator/lib/builder/om/QueryInheritanceBuilder.php
View
8 generator/lib/builder/om/QueryInheritanceBuilder.php
@@ -94,7 +94,10 @@ protected function getParentClassName()
{
$ancestorClassName = ClassTools::classname($this->getChild()->getAncestor());
if ($this->getDatabase()->hasTableByPhpName($ancestorClassName)) {
- return $this->getNewStubQueryBuilder($this->getDatabase()->getTableByPhpName($ancestorClassName))->getClassname();
+ //fix for lack of "use" statement for parent class in query subclasses
+ $builder = $this->getNewStubQueryBuilder($this->getDatabase()->getTableByPhpName($ancestorClassName));
+ $this->declareClassFromBuilder($builder);
+ return $builder->getClassname();
} else {
// find the inheritance for the parent class
foreach ($this->getTable()->getChildrenColumn()->getChildren() as $child) {
@@ -133,6 +136,9 @@ protected function addClassOpen(&$script)
$baseBuilder = $this->getStubQueryBuilder();
$this->declareClassFromBuilder($baseBuilder);
$baseClassname = $this->getParentClassName();
+
+ //add peer class declaration to have "use" statement available
+ $this->declareClassFromBuilder($this->getStubPeerBuilder());
$script .= "
/**
Something went wrong with that request. Please try again.