propelorm/Propel

Base class is missing some related entity peer class use statement

Closed this issue · 1 comments

I found out that when I've added namespace capability into some schema. It has generated some getters in Base* classes for getting foreign tables data.

The problem is that it is missing the import of related *Peer class in header of PHP file.

    public function getBuckets($criteria = null, PropelPDO $con = null)
    {
        if ($criteria === null) {
            $criteria = new Criteria(TestsuitePeer::DATABASE_NAME);
        } elseif ($criteria instanceof Criteria) {
            $criteria = clone $criteria;
        }

        if ($this->collBuckets === null) {
            if ($this->isNew()) {
               $this->collBuckets = array();
            } else {

                $criteria->add(BucketPeer::TESTSUITE_ID, $this->id);

                BucketPeer::addSelectColumns($criteria);
                $this->collBuckets = BucketPeer::doSelect($criteria, $con);
            }
        } else {
            // criteria has no effect for a new object
            if (!$this->isNew()) {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.


                $criteria->add(BucketPeer::TESTSUITE_ID, $this->id);

                BucketPeer::addSelectColumns($criteria);
                if (!isset($this->lastBucketCriteria) || !$this->lastBucketCriteria->equals($criteria)) {
                    $this->collBuckets = BucketPeer::doSelect($criteria, $con);
                }
            }
        }
        $this->lastBucketCriteria = $criteria;

        return $this->collBuckets;
    }

For example this part of the code is not importing BucketPeer.

use \BaseObject;
use \BasePeer;
use \Criteria;
use \DateTime;
use \Exception;
use \PDO;
use \Persistent;
use \Propel;
use \PropelCollection;
use \PropelDateTime;
use \PropelException;
use \PropelObjectCollection;
use \PropelPDO;
use Application\Model\Database\TestingTool\Bucket;
use Application\Model\Database\TestingTool\BucketQuery;
use Application\Model\Database\TestingTool\CampaignRedirect;
use Application\Model\Database\TestingTool\SegmentationRule;
use Application\Model\Database\TestingTool\Test;
use Application\Model\Database\TestingTool\Testsuite;
use Application\Model\Database\TestingTool\TestsuitePeer;
use Application\Model\Database\TestingTool\TestsuiteSaleEvent;
use Application\Model\Database\TestingTool\TestsuiteSaleEventQuery;
use Application\Model\Database\TestingTool\TestsuiteVisitEvent;
use Application\Model\Database\TestingTool\TestsuiteVisitEventQuery;

/**
 * Base class that represents a row from the 'testsuites' table.
 *
 *
 *
 * @package    propel.generator.Application.Model.Database.TestingTool.om
 */
abstract class BaseTestsuite extends BaseObject implements Persistent

This affected not only this class but also others. I found out that PHP5ObjectNoCollectionBuilder is missing BucketPeer class in declaredClasses property.

We've got in the system other "namespaced" schema but it has the same issue.

Ok I found the solution by myself. The issue was related with configuration of build.properties file.

There was:

propel.builder.object.class = builder.om.PHP5ObjectNoCollectionBuilder

and this property was generating model classes with dependency of *Peer classes.

When I removed the parameter and regenerated schema it was using default builder which was using *Query classes for searching the database instead.

public function getBuckets($criteria = null, PropelPDO $con = null)
    {
        $partial = $this->collBucketsPartial && !$this->isNew();
        if (null === $this->collBuckets || null !== $criteria  || $partial) {
            if ($this->isNew() && null === $this->collBuckets) {
                // return empty collection
                $this->initBuckets();
            } else {
                $collBuckets = BucketQuery::create(null, $criteria)
                    ->filterByTestsuite($this)
                    ->find($con);
                if (null !== $criteria) {
                    if (false !== $this->collBucketsPartial && count($collBuckets)) {
                      $this->initBuckets(false);

                      foreach ($collBuckets as $obj) {
                        if (false == $this->collBuckets->contains($obj)) {
                          $this->collBuckets->append($obj);
                        }
                      }

                      $this->collBucketsPartial = true;
                    }

                    $collBuckets->getInternalIterator()->rewind();

                    return $collBuckets;
                }

                if ($partial && $this->collBuckets) {
                    foreach ($this->collBuckets as $obj) {
                        if ($obj->isNew()) {
                            $collBuckets[] = $obj;
                        }
                    }
                }

                $this->collBuckets = $collBuckets;
                $this->collBucketsPartial = false;
            }
        }

        return $this->collBuckets;
    }
use \BaseObject;
use \BasePeer;
use \Criteria;
use \DateTime;
use \Exception;
use \PDO;
use \Persistent;
use \Propel;
use \PropelCollection;
use \PropelDateTime;
use \PropelException;
use \PropelObjectCollection;
use \PropelPDO;
use Application\Model\Database\TestingTool\Bucket;
use Application\Model\Database\TestingTool\BucketQuery;
use Application\Model\Database\TestingTool\CampaignRedirect;
use Application\Model\Database\TestingTool\CampaignRedirectQuery;
use Application\Model\Database\TestingTool\SegmentationRule;
use Application\Model\Database\TestingTool\SegmentationRuleQuery;
use Application\Model\Database\TestingTool\Test;
use Application\Model\Database\TestingTool\TestQuery;
use Application\Model\Database\TestingTool\Testsuite;
use Application\Model\Database\TestingTool\TestsuitePeer;
use Application\Model\Database\TestingTool\TestsuiteQuery;
use Application\Model\Database\TestingTool\TestsuiteSaleEvent;
use Application\Model\Database\TestingTool\TestsuiteSaleEventQuery;
use Application\Model\Database\TestingTool\TestsuiteVisitEvent;
use Application\Model\Database\TestingTool\TestsuiteVisitEventQuery;

Luckily the default one has no problem with use statements.

So I don't recommend using the conjunction of builder.om.PHP5ObjectNoCollectionBuilder and namespaces for schema.