0

I'm new at CakePHP and i'm facing some trouble with relationship Models. I have two models with relationship, Employee hasOne User. When i use find method, it returns all data from both table.

Example: $this->Employee->find('all'); returns Employee data and User data.

Any idea how to return only Employee data?

Edit

Searching for another question in cakePHP's docs, i found a more properly resolution for this question.

Before use find() method, just place $this-Model->unbindModel(). Right after use a find() method, the Model will back to association defined as default.

More info here: API CakePHP UnbindModel

cbaracat
  • 109
  • 2
  • 7
  • 3
    See [this answer](http://stackoverflow.com/questions/23230013/missing-from-clause-entry-for-table-grupo-cakephp/23268677#23268677) - or simply read about recursive/containable in the book. – AD7six Apr 24 '14 at 13:23
  • See [this one too](http://stackoverflow.com/questions/15562128/when-not-to-use-containable-behavior-in-cakephp-2-x) after you read up a bit about recursive/containable as AD7six said. – Nunser Apr 24 '14 at 13:27
  • I set recursive as -1 and it works. Thank you. – cbaracat Apr 24 '14 at 13:36

1 Answers1

0

Try:

$this->Employee->recursive = -1;
$this->Employee->find('all');
bigmike7801
  • 3,908
  • 9
  • 49
  • 77