Development

#3287 ([sfPropelFinderPlugin] Some mistakes in the API)

You must first sign up to be able to contribute.

Ticket #3287 (closed defect: fixed)

Opened 8 months ago

Last modified 8 months ago

[sfPropelFinderPlugin] Some mistakes in the API

Reported by: jug Assigned to: francois
Priority: major Milestone:
Component: sfPropelFinderPlugin Version: 1.0.12
Keywords: Cc:
Qualification: Unreviewed

Description

Here are two minor errors and one really minor improvement :

Plugin version :

sfPropelFinderPlugin               0.2.0-beta   # pear.symfony-project.com (symfony)

ERROR 1

Seems that the _or method doesn't exists yet :

Code :

$users = sfPropelFinder::from('User')
      ->whereLogin( $this->getRequestParameter('findme') )
      ->_or( 'email', $this->getRequestParameter('findme') )
      ->find();

Answer :

[Exception]
{sfPropelFinder} Undefined method _or

ERROR 2

I can't use new XXXFinder:

Code :

$finder = new UserFinder;

Answer:

Fatal error: Class 'UserFinder' not found

Hopefully $finder = sfPropelfinder::from('User') works well

IMPROVEMENT

Why not a orXXX and andXXX API ?

Something like this looks so nice ;) ;

$articles = sfPropelFinder::from('Article')
  ->whereTitle('hello')
  ->orContent('hello')
  ->andPublished(true)
  ->find();

It's just a little improvement...


Regards, Julien

Attachments

sfPropelFinder.php.diff (2.9 kB) - added by jug on 04/08/08 15:37:05.
sfPropelFinder.php (13.7 kB) - added by jug on 04/08/08 15:40:57.
Oops... small bug
sfPropelFinder.php.2.diff (2.9 kB) - added by jug on 04/08/08 15:41:38.
sfPropelFinderPlugin.php.diff (4.6 kB) - added by jug on 04/08/08 18:25:02.
sfPropelFinderTest.php.diff (3.9 kB) - added by jug on 04/08/08 18:25:40.

Change History

04/07/08 15:35:38 changed by jug

  • priority changed from minor to major.

I have to complete this ticket by a last error... Not a minor one this time !

Code:

    $users = sfPropelFinder::from('User')
      ->whereLogin( $this->getRequestParameter('findme') )
      ->addOr( UserPeer::EMAIL, $this->getRequestParameter('findme') )
      ->find();

SQL query executed :

SELECT [... fields for select, no problem...] FROM user WHERE user.LOGIN='julien' AND user.EMAIL='julien'

SQL query expected ;

SELECT [... fields for select, no problem...] FROM user WHERE user.LOGIN='julien' OR user.EMAIL='julien'

Am I correctly using addOr ?

04/07/08 18:27:14 changed by francois

I can't reproduce error 1, nor the more serious one... Could you try from a SVN checkout? Maybe the package wasn't properly done.

As for the XXXFinder, this will only work if you create the class before... The doc probably doesn't state it clearly enough.

04/07/08 18:37:24 changed by francois

  • summary changed from Some mistakes in the API to [sfPropelFinderPlugin] Some mistakes in the API.

04/08/08 12:25:24 changed by jug

Ok, I checked out the plugin from subversion...

So : ERROR 1 : The methods _or and _and now exist, OK

ERROR 2 : Well, you right, I missunderstood the documentation... I maybe read it too quick, OK

ERROR 3 : Still not working But it's a bit wierd... I put here some test cases, their results and what I expected...

//! configure it to fit your actual model
$class = 'Formation';   // formation
$a = 'Title';     // formation.TITLE
$b = 'Slug';      // formation.SLUG


//! Test strat here :
var_dump( sfPropelFinder::from($class)->where($a,'foo')->_or($a,'bar')->getCriteria()->toString() );
// SELECT  FROM formation WHERE (formation.TITLE=? OR formation.TITLE=?)
// OK

var_dump( sfPropelFinder::from($class)->where($a,'foo')->_or($b,'bar')->getCriteria()->toString() );
// SELECT  FROM formation WHERE formation.TITLE=? AND formation.SLUG=?
// FAILED... Expected :
// SELECT  FROM formation WHERE formation.TITLE=? OR formation.SLUG=?

var_dump( sfPropelFinder::from($class)->where($a,'foo')->_and($b,'bar')->_or($b,'stuff')->getCriteria()->toString() );
// SELECT  FROM formation WHERE formation.TITLE=? AND (formation.SLUG=? OR formation.SLUG=?)
// OK

var_dump( sfPropelFinder::from($class)->where($a,'foo')->_and($a,'bar')->_or($b,'stuff')->getCriteria()->toString() );
// SELECT  FROM formation WHERE (formation.TITLE=? AND formation.TITLE=?) AND formation.SLUG=?
// FAILED... Expected :
// SELECT  FROM formation WHERE formation.TITLE=? AND (formation.TITLE=? OR formation.SLUG=?)

var_dump( sfPropelFinder::from($class)->where($a,'foo')->_and($b,'bar')->_or($a,'stuff')->getCriteria()->toString() );
// SELECT  FROM formation WHERE (formation.TITLE=? OR formation.TITLE=?) AND formation.SLUG=?
// FAILED... Expected :
// SELECT  FROM formation WHERE formation.TITLE=? AND (formation.SLUG=? OR formation.TITLE=?)

var_dump( sfPropelFinder::from($class)->where($a,'foo')->_and($a,'bar')->_or($a,'stuff')->getCriteria()->toString() );
// SELECT  FROM formation WHERE ((formation.TITLE=? AND formation.TITLE=?) OR formation.TITLE=?)
// FAILED... Expected :
// SELECT  FROM formation WHERE formation.TITLE=? AND (formation.TITLE=? OR formation.TITLE=?)

var_dump( sfPropelFinder::from($class)->where($a,'foo')->_or($a,'bar')->_and($a,'stuff')->_or($a,'smurf')->getCriteria()->toString() );
// SELECT  FROM formation WHERE (((formation.TITLE=? OR formation.TITLE=?) AND formation.TITLE=?) OR formation.TITLE=?)
// FAILED... Expected :
// SELECT  FROM formation WHERE formation.TITLE=? OR (formation.TITLE=? AND (formation.TITLE=? OR formation.TITLE=?))

04/08/08 12:42:39 changed by francois

Hm, this seems to be a Propel bug... http://propel.phpdb.org/trac/ticket/170

Ill try to update the internals of my _or() from an addOr() to a Criterion addition.

04/08/08 15:36:40 changed by jug

Hi,

It's not really a bug, but a (boring) way of dealing with criteria / criterion in propel...

I made the fix in sfPropelFinder.php (cf. attached files) I let you check it, read my comments (marked by 'JG'), change them if...

and let me now !

Bye

04/08/08 15:37:05 changed by jug

  • attachment sfPropelFinder.php.diff added.

04/08/08 15:40:57 changed by jug

  • attachment sfPropelFinder.php added.

Oops... small bug

04/08/08 15:41:38 changed by jug

  • attachment sfPropelFinder.php.2.diff added.

04/08/08 15:50:24 changed by francois

I get your point. Could you include a diff in GNU diff format, and include in it the unit tests to prove that the condition addition works as expected?

04/08/08 18:25:02 changed by jug

  • attachment sfPropelFinderPlugin.php.diff added.

04/08/08 18:25:40 changed by jug

  • attachment sfPropelFinderTest.php.diff added.

04/08/08 18:36:00 changed by jug

OK

I add 7 tests

Note: the next improvements with this _or _and methods should be to be able to do such queries : select x from y where (a=1 or b=2) and (c=3 or d=4) select x from y where (a=1 and b=2) or (c=3 and d=4)

With this kind of syntax : $finder_a = sfPropelFinder::from('y')->whereA(1)->_orB(2); $finder_b = sfPropelFinder::from('y')->whereC(3)->_orD(4); $finder = sfPropelFinder::from('y')->where($finder_a)->_and($finder_b);

$finder_a = sfPropelFinder::from('y')->whereA(1)->_andB(2); $finder_b = sfPropelFinder::from('y')->whereC(3)->_andD(4); $finder = sfPropelFinder::from('y')->where($finder_a)->_or($finder_b);

04/09/08 12:11:24 changed by francois

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

in r8370

Thanks for the patch. I also added the magic handling of andXXX() and orXXX().