Re: Difference RedBean_OODB::find() and R::find()

38 views
Skip to first unread message

gabor

unread,
May 17, 2013, 2:56:54 PM5/17/13
to redbe...@googlegroups.com



Hi,

1.
Instead of OODB try using RedBean_Finder.
The OODB find() method is just as powerful but more complex, Finder find() is easier and more like the find method in the R-façade.

2.
That's the price of evolution, the API can be a bit funky at times (but it works, it's just the naming).
The instance methods have always been 'more complex' than their façade counterparts, however because people like the façade methods so much (yet preferred instances) I had to re-create some of them.

All functionality is available outside the façade, however sometimes the names of the methods slightly differ.

cheers,
Gabor







On Friday, May 17, 2013 11:21:53 AM UTC+2, Dennis Haarbrink wrote:
Since I generally don't like to use static methods because it makes it hard/near impossible to test, I don't use the R façade. I make sure I have access to a RedBean_OODB instance.

Now I wanted to load some beans but having trouble specifying the conditions. The OODB::find() signature is as follows:
public function find($type, $conditions = array(), $addSQL = null, $all = false)

Where Conditions need to take form:
array(
  'PROPERTY' => array( POSSIBLE VALUES... 'John', 'Steve' )
  'PROPERTY' => array( POSSIBLE VALUES... )
);

Which makes it VERY restricted.

I want a query like:
select * from table where property <> 'somevalue';

It seems that is not possible with the OODB implementation.
I even tried OODB::find('user', array(1 => 1), 'and property<>"value"');


I basically have two questions:
1. How do I accomplish this without resorting to R ?
2. Why do the two have such different find() implementations?

Dennis Haarbrink

unread,
May 21, 2013, 3:49:49 AM5/21/13
to redbe...@googlegroups.com
Hi Gabor,

Thanks for the clarification.
RedBean_Finder does what I want!

One last thing however, could you give me an example of how I would do this using the OODB::find() method? It really bugs me that I don't know how to use it and I can't really find any good documentation.

Thanks!


--
You received this message because you are subscribed to the Google Groups "redbeanphp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redbeanorm+...@googlegroups.com.
To post to this group, send email to redbe...@googlegroups.com.
Visit this group at http://groups.google.com/group/redbeanorm?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

gabor

unread,
May 21, 2013, 2:23:33 PM5/21/13
to redbe...@googlegroups.com

Of course.

Explanation:

$oodb->find( $type, $conditions, $addSql, $all );

$type -> the type of bean you're looking for
$conditions -> an array of the form:

array( 'name' => array( 'Pete', 'Sarah' ), 'department' => array('sales', 'support') )

$addSql -> additional sql, this can be anything like ' and age > 50 ', you can also pass an array with SQL and bindings: array(' age > ?', array(50))
$all -> this boolean flag determines how to glue $addSql to $conditions - if $addSql contains additional conditions you want to concat the strings using ' AND ' (use FALSE), otherwise if you don't want to filter any further (i.e. you want ALL results from the conditions) use TRUE to glue with an empty string. If this parameter did not exist you would not be able to use $addSql snippets like ' ORDER BY name ASC ' (you would have to use ' 1 ORDER BY name ASC' which is ugly).

That's how the find() method in OODB works.
Does this clarify the use of the method ?

Cheers,
Gabor
Reply all
Reply to author
Forward
0 new messages