EzDevInfo.com

Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for PHP >= 5.4 Propel, The Blazing Fast Open-Source PHP 5.4 ORM

Propel2, createdBy field

Let's say I have model "Question". Every question is created by user (current user). How to "auto" update createdBy to current.user

In Doctrine2 I should have event listener with dependency on security.context. And event will subscribe for preSave(), setting $question->setCreatedBy( $context->getToken()->getUser());

How to achieve this with Propel2 ? I could set createdBy in controller, but this is ugly :(

I could write custom behavior, but how to access security.context from the behavior ?


Source: (StackOverflow)

Propel2 collections disappear on update

My colleagues and I have written a dozen web applications using Symfony2 and Propel1. We are now trying to use Propel2 but encounter the following problem when migrating an application from Propel1 to Propel2.

In our simple schema, a parent object, Auteur (author) possesses a collection of children Livre (book) objects. We use a Symfony form to create the Auteur with a collection of Livres objects. In this case, the Auteur and Livres are correctly persisted in the database.

However, when we update the Auteur object without touching the collection of Livres, the collection is emptied.

We could not determine whether this was a bug in Propel2 (or less probably Symfony2) or if we are doing things incorrectly. The almost same code (somewhat adapted to Propel1) works without a problem: the Livres collection is not emptied on Auteur update.

We have published a minimal project reproducing the problem. To test it with Propel2, please do:

git clone https://github.com/spyrit/MinimalS2P2.git
cd MinimalS2P2
composer install
app/console propel:build
app/console propel:migration:diff
app/console propel:migration:migrate

To test it with Propel1, use to the propel1 branch:

git checkout propel1
composer install
app/console propel:build
app/console propel:migration:generate-diff
app/console propel:migration:migrate

We will be grateful on any hint concerning this issue.


Source: (StackOverflow)

Advertisements

Is there a nice way of getting all the primary key values of a model with Propel2?

I want to get all the primary key values of a collection. I'm currently doing this:

$pks = [];
foreach(MyModelQuery::create()->findByToUid($this->getUserId()) as $myModel){
  $pks[] = $myModel->getPrimaryKey();
}

Is there a way to get the collection to just return me an array of primary keys?


Source: (StackOverflow)