Wednesday, November 14, 2012

Re: Yet another "Call to a member function find on a non-object" error

I didn't post any code because any piece of code where I try to call a related model I get the error, but for example, here's one:

$slides = $this->Module->Slide->find('all', array('conditions' => array('Module.id' => $id)));

I've since changed the code to a poor workaround, so I'll change it back later to get a stack trace. 

On Wednesday, November 14, 2012 12:14:34 AM UTC-5, bs28723 wrote:
I don't think you provided enough info for anyone to help you. 

Please provide the function and point out the line that is getting the error. 

Thanks,
Bill Stoltz

On Nov 13, 2012, at 10:31 PM, "Andrew Johnston [via CakePHP]" <[hidden email]> wrote:

I know this post gets written every couple of months, and I swear that I've read through all of the back posts, yet can't find a solution that works.

Whenever I try to call related data from one of my models, I get the above error. Below is the relationship code for each model.

class Slide extends AppModel {
public $name = 'Slide';
public $belongsTo =  array(
'Module' => array(
'className' => 'Module',
'foreignKey' => 'module_id',
));

class Module extends AppModel {
public $name = 'Module';
public $hasMany = array(
'Slide' => array(
'className'  => 'Slide',
'foreignKey' => 'module_id',
'order' => 'Slide.position ASC',
'dependent' => true
)
);
public $belongsTo = array(
'Creator' => array(
'className' => 'User'));
public $hasAndBelongsToMany = array(
'Learner' => array(
  'className'              => 'User',
           'joinTable'              => 'modules_users',
           'foreignKey'             => 'module_id',
           'associationForeignKey'  => 'users_id',
           'unique'                 => 'keepExisting',
));

class User extends AppModel {
public $name = 'User';
public $uses = 'users';
public $hasMany = array(
'OModule' => array(
'className' => 'Module',
'foreignKey' => 'users_id',
'order' => 'Module.created DESC'
));
public $hasAndBelongsToMany = array(
'Module' => array( //We gotta remember this later...
  'className'              => 'Module',
           'joinTable'              => 'modules_users',
           'foreignKey'             => 'user_id',
           'associationForeignKey'  => 'module_id',
           'unique'                 => 'keepExisting',
));

I've tried to adhere to all of the requirements outlined in the CookBook, but I know I must be doing something wrong. Any help is appreciated. Thanks in advance.

Andrew

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 



If you reply to this email, your message will be added to the discussion below:
http://cakephp.1045679.n5.nabble.com/Yet-another-Call-to-a-member-function-find-on-a-non-object-error-tp5712251.html
To start a new topic under CakePHP, email [hidden email]
To unsubscribe from CakePHP, click here.
NAML


View this message in context: Re: Yet another "Call to a member function find on a non-object" error
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: