Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use the findBy magic find functions WITH $fields optional parameters?

Was considering utilizing the magic findBy functions on a model today and encountered an issue when attempting to set optional parameters for the function. Here is what I tried.

$result = $this->findById($id['Alpha.name']);

So to explain, I'm attempting to find a record with a specific id and only return the value of the name field. According to the documentation, there is a way to do this.

The findBy magic functions also accept some optional parameters: findBy<fieldName>(string $value[, mixed $fields[, mixed $order]]);

CakePHP 1.3 Book :: findBy

When I do a simple findBy($id) I do get a result set. But with parameters, I get nothing. I know there are other ways to do this but was just curious if anyone has had any success using these magic functions with additional parameters?

like image 247
generalopinion Avatar asked Jun 04 '11 22:06

generalopinion


1 Answers

try this:

$result = $this->findById($id, array('Alpha.name'));

where $id is an id of record you're searching for and Alpha.name is a field you need (e.g. name from model Alpha)

like image 127
zergussino Avatar answered Nov 15 '22 10:11

zergussino