Dave
heres the exact OperationParticipant model:
class OperationParticipant extends OperationAppModel {
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'user_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or
'update' operations
),
),
'operation_id' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or
'update' operations
),
),
);
//The Associations below have been created with all possible keys,
those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Operation' => array(
'className' => 'Operation',
'foreignKey' => 'operation_id',
'conditions' => '',
'fields' => '',
'order' => '',
'counterCache' => true
)
);
}
and the Operation controller method doing the work:
/**
* view method
*
* View an operation
*
* @param string $id
* @return void
*/
public function view($id = null) {
$this->Operation->id = $id;
if (!$this->Operation->exists()) {
throw new NotFoundException(__('Invalid operation'));
}
$this->Operation->Behaviors->attach('Containable');
$this->set('operation', $this->Operation->find('first', array(
'contain' => array(
'User',
'OperationType',
'OperationParticipant' => array('User')
),
'conditions' => array(
'Operation.id' => $id
)
)
));
}
and still getting the error described...using cake 2.1.5 if that helps?
On Tue, Oct 9, 2012 at 9:14 AM, Greg Skerman <[email protected]> wrote:
> The only thing I can think of is that User doesn't have an association
> (baking the app would make it do so).
>
> Because Operation is a plugin which may or may not be there, User doesn't
> have the association. But given i don't need to query it from the user
> side, I don't need the association there, do i?
>
>
>
> On Mon, Oct 8, 2012 at 10:52 PM, Dave M. <[email protected]> wrote:
>
>> I suspect there is something else going on specific to your setup.
>>
>> I baked up a quick test app and had no problems at all. I didn't alias
>> the association at all.
>>
>> My model names and associations were the same as yours.
>>
>> $this->Operation->find('all', array(
>> 'contain' => array(
>> 'User',
>> 'OperationType',
>> 'OperationParticipant' => array('User')
>> )
>> );
>>
>> Yielded this result:
>>
>> array(
>> (int) 0 => array(
>> 'Operation' => array(
>> 'id' => '1',
>> 'user_id' => '1',
>> 'descr' => 'fooo',
>> 'operation_type_id' => '1'
>> ),
>> 'User' => array(
>> 'id' => '1',
>> 'username' => 'aaa'
>> ),
>> 'OperationType' => array(
>> 'id' => '1',
>> 'descr' => 'Foo'
>> ),
>> 'OperationParticipant' => array(
>> (int) 0 => array(
>> 'id' => '1',
>> 'user_id' => '1',
>> 'operation_id' => '1',
>> 'User' => array(
>> 'id' => '1',
>> 'username' => 'aaa'
>> )
>> ),
>> (int) 1 => array(
>> 'id' => '2',
>> 'user_id' => '2',
>> 'operation_id' => '1',
>> 'User' => array(
>> 'id' => '2',
>> 'username' => 'bbb'
>> )
>> )
>> )
>> )
>> )
>>
>> I'm still thinking about this.
>>
>> On Monday, October 8, 2012 7:45:39 AM UTC-4, José Lorenzo wrote:
>>>
>>> You need the alias as cricket said and in your find you need 'contain'
>>> => array('OpUser', 'User')
>>>
>>> El lunes, 8 de octubre de 2012 01:50:05 UTC+2, Greg escribió:
>>>>
>>>> Sure have. Its containable that i'm suspecting is the problem.. Its
>>>> almost as though it binds the model on the first level of contain, but then
>>>> fails to rebind it after. If i turn containable off I can query the model
>>>> with ->find();, but with containable on ->find() throws a non-existant
>>>> method/non-existant object error.
>>>>
>>>>
>>>> On Mon, Oct 8, 2012 at 2:17 AM, Dave M. <[email protected]> wrote:
>>>>
>>>>> another wild guess: have you attached the Containable behavior?
>>>>>
>>>>> In your AppModel:
>>>>> public $actsAs = array('Containable');
>>>>>
>>>>> -dave
>>>>>
>>>>> On Saturday, October 6, 2012 2:58:54 AM UTC-4, Greg wrote:
>>>>>
>>>>>> Sorry to keep bumping, but this is really doing my head in...
>>>>>>
>>>>>> The only "solution" i have is to load the data without the contained
>>>>>> users, and then call the users with ajax after the page has loaded -
>>>>>> which
>>>>>> seems a bit daft to me.
>>>>>>
>>>>>> On Tue, Oct 2, 2012 at 10:37 PM, Greg Skerman <[email protected]>wrote:
>>>>>>
>>>>>>> So even after aliasing everything, the User model appears to become
>>>>>>> unbound from the OperationParticipant model and doesn't get rebound by
>>>>>>> containable...
>>>>>>>
>>>>>>> anybody got any clue?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Tue, Oct 2, 2012 at 7:54 AM, Greg Skerman <[email protected]>wrote:
>>>>>>>
>>>>>>>> Yeah no dice :( had tried something similar to that before.
>>>>>>>>
>>>>>>>> * Model "OperationParticipant" is not associated with model
>>>>>>>> "OPUser"*
>>>>>>>>
>>>>>>>>
>>>>>>>> On Tue, Oct 2, 2012 at 4:05 AM, lowpass <[email protected]>wrote:
>>>>>>>>
>>>>>>>>> Just a wild guess: in the OperationParticipant model, try changing
>>>>>>>>> the
>>>>>>>>> alias for User. Something like:
>>>>>>>>>
>>>>>>>>> public $belongsTo = array(
>>>>>>>>> 'OPUser' => array(
>>>>>>>>> 'className' => 'User',
>>>>>>>>> ...
>>>>>>>>>
>>>>>>>>> And then change the contain block to have 'OperationParticipant'
>>>>>>>>> =>
>>>>>>>>> array('OPUser')
>>>>>>>>>
>>>>>>>>> On Mon, Oct 1, 2012 at 3:05 AM, Greg Skerman <[email protected]>
>>>>>>>>> wrote:
>>>>>>>>> > I've been wracking my brain over this for a few hours and its
>>>>>>>>> doing my head
>>>>>>>>> > in.
>>>>>>>>> >
>>>>>>>>> > Consider the following models and associations:
>>>>>>>>> >
>>>>>>>>> > Operation belongsTo User, OperationType and hasMany
>>>>>>>>> OperationParticipant
>>>>>>>>> > OperationType hasMany Operation
>>>>>>>>> > OperationParticipant belongsTo User, Operation
>>>>>>>>> >
>>>>>>>>> > if I dump out the contents of OperationParticipant in the
>>>>>>>>> > OperationParticipants controller, I get exactly what I would
>>>>>>>>> expect - a list
>>>>>>>>> > of OperationParticipants and the associated list of Users.
>>>>>>>>> Obviously User is
>>>>>>>>> > correctly associated with OperationParticipant
>>>>>>>>> >
>>>>>>>>> > The problem comes when I want to call up an Operation and list
>>>>>>>>> the users who
>>>>>>>>> > are participating.
>>>>>>>>> >
>>>>>>>>> > $this->Operation->find('all', array(
>>>>>>>>> > 'contain' => array(
>>>>>>>>> > 'OperationType', 'User', 'OperationParticipant' =>
>>>>>>>>> array('User')
>>>>>>>>> > )
>>>>>>>>> > )
>>>>>>>>> > );
>>>>>>>>> >
>>>>>>>>> > I get
>>>>>>>>> >
>>>>>>>>> > Model "OperationParticipant" is not associated with model "User"
>>>>>>>>> >
>>>>>>>>> > If, from within the context of the Operations controller I do
>>>>>>>>> > pr($this->Operation->**Operation**Participants->find('**all')));
>>>>>>>>> I get no
>>>>>>>>> > associated data back for OperationParticipants.
>>>>>>>>> >
>>>>>>>>> > Adding OperationParticipants to the $uses property yields the
>>>>>>>>> same result,
>>>>>>>>> > no associated data.
>>>>>>>>> >
>>>>>>>>> > I've done deep contains before, and I cannot for the life of me
>>>>>>>>> understand
>>>>>>>>> > why this is acting up.
>>>>>>>>> >
>>>>>>>>> >
>>>>>>>>> > Here are the associations:
>>>>>>>>> >
>>>>>>>>> >
>>>>>>>>> > OperationParticipant.php
>>>>>>>>> >
>>>>>>>>> > /**
>>>>>>>>> > * belongsTo associations
>>>>>>>>> > *
>>>>>>>>> > * @var array
>>>>>>>>> > */
>>>>>>>>> > public $belongsTo = array(
>>>>>>>>> > 'User' => array(
>>>>>>>>> > 'className' => 'User',
>>>>>>>>> > 'foreignKey' => 'user_id',
>>>>>>>>> > 'conditions' => '',
>>>>>>>>> > 'fields' => '',
>>>>>>>>> > 'order' => ''
>>>>>>>>> > ),
>>>>>>>>> > 'Operation' => array(
>>>>>>>>> > 'className' => 'Operation',
>>>>>>>>> > 'foreignKey' => 'operation_id',
>>>>>>>>> > 'conditions' => '',
>>>>>>>>> > 'fields' => '',
>>>>>>>>> > 'order' => '',
>>>>>>>>> > 'counterCache' => true
>>>>>>>>> > )
>>>>>>>>> > );
>>>>>>>>> >
>>>>>>>>> >
>>>>>>>>> > Operation.php
>>>>>>>>> >
>>>>>>>>> > /**
>>>>>>>>> > * belongsTo associations
>>>>>>>>> > *
>>>>>>>>> > * @var array
>>>>>>>>> > */
>>>>>>>>> > public $belongsTo = array(
>>>>>>>>> > 'OperationType' => array(
>>>>>>>>> > 'className' => 'OperationType',
>>>>>>>>> > 'foreignKey' => 'operation_type_id',
>>>>>>>>> > 'conditions' => '',
>>>>>>>>> > 'fields' => '',
>>>>>>>>> > 'order' => ''
>>>>>>>>> > ),
>>>>>>>>> > 'User' => array(
>>>>>>>>> > 'className' => 'User',
>>>>>>>>> > 'foreignKey' => 'user_id',
>>>>>>>>> > 'conditions' => '',
>>>>>>>>> > 'fields' => '',
>>>>>>>>> > 'order' => ''
>>>>>>>>> > )
>>>>>>>>> > );
>>>>>>>>> >
>>>>>>>>> > /**
>>>>>>>>> > * hasMany associations
>>>>>>>>> > *
>>>>>>>>> > * @var array
>>>>>>>>> > */
>>>>>>>>> > public $hasMany = array(
>>>>>>>>> > 'OperationParticipant' => array(
>>>>>>>>> > 'className' => 'OperationParticipant',
>>>>>>>>> > 'foreignKey' => 'operation_id',
>>>>>>>>> > 'dependent' => false,
>>>>>>>>> > 'conditions' => '',
>>>>>>>>> > 'fields' => '',
>>>>>>>>> > 'order' => '',
>>>>>>>>> > 'limit' => '',
>>>>>>>>> > 'offset' => '',
>>>>>>>>> > 'exclusive' => '',
>>>>>>>>> > 'finderQuery' => '',
>>>>>>>>> > 'counterQuery' => ''
>>>>>>>>> > )
>>>>>>>>> > );
>>>>>>>>> >
>>>>>>>>> >
>>>>>>>>> > OperationType.php
>>>>>>>>> >
>>>>>>>>> > /**
>>>>>>>>> > * hasMany associations
>>>>>>>>> > *
>>>>>>>>> > * @var array
>>>>>>>>> > */
>>>>>>>>> > public $hasMany = array(
>>>>>>>>> > 'Operation' => array(
>>>>>>>>> > 'className' => 'Operation',
>>>>>>>>> > 'foreignKey' => 'operation_type_id',
>>>>>>>>> > 'dependent' => false,
>>>>>>>>> > 'conditions' => '',
>>>>>>>>> > 'fields' => '',
>>>>>>>>> > 'order' => '',
>>>>>>>>> > 'limit' => '',
>>>>>>>>> > 'offset' => '',
>>>>>>>>> > 'exclusive' => '',
>>>>>>>>> > 'finderQuery' => '',
>>>>>>>>> > 'counterQuery' => ''
>>>>>>>>> > )
>>>>>>>>> > );
>>>>>>>>> >
>>>>>>>>> >
>>>>>>>>> >
>>>>>>>>> > The users model does not have the association included,
>>>>>>>>> Operations is a
>>>>>>>>> > plugin which may not always be there so I've not included the
>>>>>>>>> hasMany (and
>>>>>>>>> > there is no reason to read the data back the other way, i.e. I
>>>>>>>>> have no
>>>>>>>>> > requirement to get a list of Users and find their associated
>>>>>>>>> Operations -
>>>>>>>>> > only Operations, and find their associated users.
>>>>>>>>> >
>>>>>>>>> > Can anyone shed any light?
>>>>>>>>> >
>>>>>>>>> > --
>>>>>>>>> > Like Us on FacekBook
>>>>>>>>> > https://www.facebook.com/**CakeP**HP<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 [email protected].
>>>>>>>>>
>>>>>>>>> > To unsubscribe from this group, send email to
>>>>>>>>> > cake-php+u...@**googlegroups.com**.
>>>>>>>>>
>>>>>>>>> > Visit this group at http://groups.google.com/**group**
>>>>>>>>> /cake-php?hl=en <http://groups.google.com/group/cake-php?hl=en>.
>>>>>>>>> >
>>>>>>>>> >
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Like Us on FacekBook
>>>>>>>>> https://www.facebook.com/**CakeP**HP<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 [email protected].
>>>>>>>>> To unsubscribe from this group, send email to cake-php+u...@**
>>>>>>>>> googlegroups.com**.
>>>>>>>>>
>>>>>>>>> Visit this group at http://groups.google.com/**group**
>>>>>>>>> /cake-php?hl=en <http://groups.google.com/group/cake-php?hl=en>.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>> --
>>>>> Like Us on FaceBook
>>>>> https://www.facebook.com/**CakePHP<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 [email protected].
>>>>> To unsubscribe from this group, send email to
>>>>> [email protected]**.
>>>>> Visit this group at
>>>>> http://groups.google.com/**group/cake-php?hl=en<http://groups.google.com/group/cake-php?hl=en>
>>>>> .
>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>> 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 [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> Visit this group at http://groups.google.com/group/cake-php?hl=en.
>>
>>
>>
>
>
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.