Development

#1229 ([sfPropelParanoidBehavior] (FIX INCLUDED) sfPropelParanoidBehavior::DoSelectRS doesn't working.)

You must first sign up to be able to contribute.

Ticket #1229 (closed defect: wontfix)

Opened 1 year ago

Last modified 1 month ago

[sfPropelParanoidBehavior] (FIX INCLUDED) sfPropelParanoidBehavior::DoSelectRS doesn't working.

Reported by: tsukimiya Assigned to: fabien
Priority: major Milestone: plugins
Component: sfPropelParanoidBehaviorPlugin Version: 1.0.2
Keywords: Cc:
Qualification: Unreviewed

Description

I edited propel.ini. and executed "symfony propel-build-model".

And, sfPropelBehavior::add('ModelName?', array('paranoid')); was added to the model class.

But, sfPropelParanoidBehavior::DoSelectRS is not executed.

Change History

01/23/07 23:54:46 changed by Aloysius.Lim

  • priority changed from minor to major.
  • version changed from 1.0.0-beta1 to 1.0.0-beta4.

After 4 hours of debugging, I found that this was caused by two things:

1) The lib/model/Model.php class is only loaded AFTER your action which calls doSelectRS(), so the hooks are loaded too late.

2) The hook name Peer:doSelectRS is wrong.

FIX:

1) Move all the

sfPropelBehavior::add('Model', array('paranoid'));

statements into apps/myApp/config/config.php, so that the hooks are registered before the actions are executed.

2) Change this line in plugins/sfPropelParanoidBehavior/config/config.php:

sfPropelBehavior::registerHooks('paranoid', array(
  ':delete:pre' => array('sfPropelParanoidBehavior', 'preDelete'),
  'Peer:doSelectRS' => array('sfPropelParanoidBehavior', 'doSelectRS'),
));

to

sfPropelBehavior::registerHooks('paranoid', array(
  ':delete:pre' => array('sfPropelParanoidBehavior', 'preDelete'),
  'Peer:addDoSelectRS' => array('sfPropelParanoidBehavior', 'doSelectRS'),
));

Unfortunately I do not have write permissions in svn, so somebody else will have to commit these changes.

01/24/07 04:26:06 changed by Aloysius.Lim

  • summary changed from [sfPropelParanoidBehavior] sfPropelParanoidBehavior::DoSelectRS doesn't working. to [sfPropelParanoidBehavior] (FIX INCLUDED) sfPropelParanoidBehavior::DoSelectRS doesn't working..

03/16/07 19:29:06 changed by francois

  • owner set to fabien.
  • component set to cache.

I can't understand how the add can be executed too late. You have to put it at the end of the class you want to extend, not somewhere else.

As for the second point, patch attached to #1585 should solve the problem.

03/16/07 19:30:38 changed by francois

  • component changed from cache to sfPropelParanoidBehaviorPlugin.

06/05/07 16:28:27 changed by Markus.Milkereit

  • version changed from 1.0.0-beta4 to 1.0.2.

I had the same problem Aloysius.Lim reported, the hooks worked fine for me at the writing side ("delete" really does a "update deleted_at"). But the reader-methods doSelect etc. did not change. There was no "where deleted_at is null" - until I did what he recommended:

Moving

sfPropelBehavior::add('Model', array('paranoid'));

to /app/config/config.php - that did the trick.

I have patched the sfPeerBuilder as mentioned above.

07/31/07 10:05:00 changed by tamcy

The reason add executed so late is due to autoloading. In the old days, generated peer classes had a line that include against its related models (and vice versa). So the peer & object classes were always loaded in pair.

Now such require_once/include_once was removed, model and peer classes are no longer loaded at the same time. If the "add behavior" code is placed inside the model classes, the hook to doSelectRS won't be registered when calling FooPeer::doSelect the first time because the model class hasn't yet loaded.

Similarly, moving the registration to peer class would cause for example the "preSave" hook not working until the peer class is loaded.

But it is also not a good idea to add back the include/require pair because I found this can easily lead to circular autoloading that causes fatal error.

(follow-up: ↓ 8 ) 09/08/07 15:07:31 changed by davedash

  • status changed from new to closed.
  • resolution set to wontfix.

This is a problem with Propel, so there is no symfony based fixed.

(in reply to: ↑ 7 ) 09/08/07 16:00:50 changed by l2k

  • qualification set to Unreviewed.

Replying to davedash:

This is a problem with Propel, so there is no symfony based fixed.

Is it? Looks more like a autoloading/mixin issue to me.

10/17/07 12:29:47 changed by francois

  • qualification set to Unreviewed.

There is one easy solution, which is to add an include_once statement at the bottom of both the model and the peer class, including a file where the behavior is added for this class.