sfPropelFinder is like jQuery for Propel

Are you tired of writing long Criteria definitions for simple queries? Do you sometimes wish that symfony had an ActiveRecord (even if it is not really possible in PHP5 as of now)? Do you feel that the world of Javascript has changed since jQuery came up? Do you like the way sfFinder and sfTestBrowser work?

Then take a look at this:

// With Peer and Criteria
$c = new Criteria()
$c->add(ArticlePeer::TITLE, '%world', Criteria::LIKE);
$c->add(ArticlePeer::IS_PUBLISHED, true);
$c->addAscendingOrderByColumn(ArticlePeer::CREATED_AT);
$articles = ArticlePeer::doSelect($c);

// with sfPropelFinder
$articles = sfPropelFinder::from('Article')->
  whereTitle('like', '%world')->
  whereIsPublished(true)->
  orderByCreatedAt()->
  find();


This example shows the philosophy of a new symfony plugin I just commited. Check it out if you're interested.

Possibly related posts (automatically generated):

26 Comments so far

  1. André Neves on March 27th, 2008

    Brilliant!! great work! Thank you.

  2. Skyblaze on March 27th, 2008

    Wow amazing!! I have waited for a thing like this and like active record(coming from rails) here in symfony!! In the next versions i would implement the OR keyword between where clauses also. And of course joins :) Anyway great work i will try it ;)

  3. João Barbosa on March 27th, 2008

    Very nice :)

    It's only a matter of taste, although the with sfPropelFinder you write less code.

  4. David Brewer on March 27th, 2008

    If this had existed a year ago I might not have gone through the pain of switching to Doctrine. :-)

    This syntax looks a bit like Doctrine's approach to building queries using method chaining, which I quite like. Ironically, the Doctrine folks are talking about introducing a Criteria-like object to handle the most complex of query-building problems. Maybe in a couple years the projects will be so similar they will just merge: Doctrel? Propine?

  5. Ryan Weaver on March 27th, 2008

    I DO love jQuery! I especially like that this approach allows you to chain the request into just one line of code. I look forward to diving into it.

    Are there any major dependencies that would make it difficult to get working on sf 1.1 with Propel 1.3?

  6. Dustin Whittle on March 27th, 2008

    Yet another great plugin from Francois! Thanks, this makes propel painless.

  7. NiKo on March 27th, 2008

    Looks very great and useful, congrats. But just one thought: why didn't you submit a patch for sfPropelImpersonatorPlugin?

  8. fzaninotto on March 27th, 2008

    @NiKo: I guess the two plugins should merge, I agree, but I didn't make contact with Romain yet.

  9. Hugo on March 27th, 2008

    Good job François ;)

  10. Cedric Sadai on March 27th, 2008

    Very exciting work. Thank you Francois.

  11. Ian P. Christian on March 27th, 2008

    It looks very nice, and is only a couple of hundred lines of code which wrap existing functionality in propel - so no needless bloat which is nice.

    I’d like to point out that doctrine does more then just provide a nicer way of doing queries though. Inheritence for one….

    This is a great step in the right direction for Propel, don’t don’t be fooled into thinking suddently doctrine is pointless :)

  12. Romain Dorgueil (hartym) on March 27th, 2008

    Yes, a merge with sfPropelImpersonator is a very good idea, since yesterday I also refactored relations in their own classes, so the population/relation fetching is less magic and more atomic.

    I'll have a look soon on how this could be possible, the idea should remain being able to use only the components we need for a given task. As we were talking about morning, no need to use PropelImpersonator for simple selects, but sfPropelFinder could switch automatically to use it if relations are out of propel's scope.

    But then, I'm starting to think again that peer classes are very badly designed. Thoose magics static i-resolve-the-three-cases-you-ll-not-often-use classes could maybe then replaced by Finder classes, ie ArticleFinder would replace Criteria and Peer class at the same time.

    I will, if i find some time for it, try to benchmark ArticlePeer::doSelect(new Criteria()) vs { $peer = new sfPropelObjectPeerImpersonator('Article'); $peer->doSelect(new Criteria()); }

    If the difference is not very significant, peer classes could be thrown away?

    Well maybe i'm just dreaming :p

    ps: btw, I don't know how Propel 1.3 makes this evolve. Is there better solutions for relations and queries yet?

    and ps2: i agree pookey, sfPopi, as I like to call it, was just initially started as a hack to make propel projects optimisation less painfull. Still I'm a big fan of doctrine, and I very much hope that the recent evolution in the seriousness of feature-release relation will help doctrine to be enterprise ready very soon.

  13. alexis on March 27th, 2008

    yu'r right guy !

    to be continued !

  14. Paolo Mainardi on March 27th, 2008

    Very good work Francois! Thank you for your time spent to increase the power of Symfony ;)

  15. FX Poster on March 27th, 2008

    Waiting for joins in your plugin :)

  16. François Zaninotto on March 27th, 2008

    @FX: Are you kidding? I just added them this afternoon...

  17. halfer on March 28th, 2008

    François, many thanks for this contribution. Needless to say you should ignore apparently ungrateful individuals such as FX - some people want everything for free and done for them yesterday ;)

  18. FX Poster on March 28th, 2008

    Well, when I saw the plugin page (on sf trac) - joins were in the todo. :) I've already seen that you'd added them.

    PS. I gorgot something... Thanks for your plugin! :)

  19. FX Poster on March 28th, 2008
    • Forgot
  20. vinilios on March 30th, 2008

    simply amazing !!! thanks for the contribution

  21. Markus.Staab on March 31st, 2008

    thanks for the plugin.

    why do you have a method findOne when it could easily be written with find(1)

    also a innerJoin/outerJoin/leftJoin/rightJoin is missing..

    what about selecting records using a aggregate function, something like MAX('id')

  22. François Zaninotto on March 31st, 2008

    @Markus:

    • Because find(1) returns an array, and findOne() returns a single Propel object.
    • $finder->join('Comment', Criteria::LEFT_JOIN) already works.
    • This is exactly the limit of the things that are already done by sfPropelImpersonatirPlugin, for which I just want to write an API but not reinvent the wheel. Hartym will assess the plugin soon and see how to integrate the two plugins.
  23. Markus.Staab on April 5th, 2008

    Hi Francois,

    you should comment the difference of find(1) and findOne() in the readme...

    Thanks, Markus

  24. pawel_k on April 8th, 2008

    Great job, it's really useful :)

    one note: updateLatestQuery() can only work when Propel::getConnection() returns sfDebugConnection (generally in dev environment), PgSQLConnection/MySQLConnection don't have this method...

  25. simo on June 7th, 2008

    Does that work with i18n enabled?

  26. [...] sfPropelFinder is like jQuery for Propel [...]