Skip to content

Hint, never ever name a column "database_name" or "table_name" when you are using PHP's Propel

Defining a column name inside a table definition "database_name" or "table_name" will result in duplicated generated constant definition which will be an evil fail you have to debug for some minutes.

Super hint! Name them "the_database_name" and "the_table_name" :-D.

Translate to de es fr it pt ja

"vendor/propel/propel1/generator/bin/phing.php: Permission denied"

I had to deal with an older project and wanted to update my database orm-code.

vendor/propel/propel1/generator/bin/phing.php: Permission denied

This error message is really general and it took me a while to find the solution. For whatever reason, the file "phing.php" has lost its execute flag. To fix this error, all you have to do is:

chmod +x vendor/propel/propel1/generator/bin/phing.php

This is it.

Translate to de es fr it pt ja

Propel, the PropelOnDemandFormatter, self loaded runtime properties and your special reload data if needed usecase- howto

Propel column representation offering the option to add some business logic inside. We are making this from time to time by enriching the existing object with more data, but only when a method is called explicit.


class MyTable extends BaseMyTable
{
    /** @var null|\My\Enriched\MyTable\Data */
    protected $enrichedData;

    /**
     * @return null|\My\Enriched\MyTable\Data
     */
    public function getEnrichedData()
    {
        //prevent reloading enriched data if this method is called more than once
        if ($this->noEnrichedDataYetLoaded()) {
            //do something heavy data lifting
            $this->enrichedData = $this->tryToLoadEnrichedData();
        }

        return $this->enrichedData;
    }

    /**
     * @return bool
     */
    private function noEnrichedDataYetLoaded()
    {
        return (is_null($this->enrichedData));
    }
}

If you would use the corrosponding MyTableQuery object in combination with a PropelOnDemandFormatter and iterating over an collection after calling find(), you would get the same enriched data for different MyTable objects.
Why? Because the PropelOnDemandFormatter does a smart thing by reusing the on MyTable object and "just" updating the properties.
Following is a workaround I am using to fix this (totally right) behaviour. Anyways, be caution if you do things like that. This should not be your regular way of doing it.


class MyTable extends BaseMyTable
{
    /** @var null|\My\Enriched\MyTable\Data */
    protected $enrichedData;

/** @var int */
protected $myId;

/**
 * @return null|\My\Enriched\MyTable\Data
 */
public function getEnrichedData()
{
    //prevent reloading enriched data if this method is called more than once
    if ($this->noEnrichedDataYetLoaded()) {
        //do something heavy data lifting
        $this->enrichedData = $this->tryToLoadEnrichedData();
        $this->myId         = $this->getId();
    }

    return $this->enrichedData;
}

/**
 * @return bool
 */
private function noEnrichedDataYetLoaded()
{
    return (
        ($this->myId == $this->getId())
        && (is_null($this->enrichedData))
    );
}

}

Translate to de es fr it pt ja

Reminder of the Propel Bug 734 - update() with limit() and a workaround

Just because we ran into this issue again. There is known and serious bug in propel whenever you use "update()" in combination with "limit()".
Our workaround right now is to replace the code.


//this will update all entry with the content "bar" in the column "foo"
MyQuery::create()
    ->filterByFoo('bar')
    ->limit(100)
    ->update(
        array(
            'Foo' => 'baz'
        )
    );

//this will only update 100 rows $ids = (array) MyQuery::create() ->filterByFoo('bar') ->limit(100) ->select( array( 'Id' ) ) ->find();

MyQuery::create() ->filterById($ids) ->update( array( 'Foo' => 'baz' ) );

Translate to de es fr it pt ja