the following is not correct:
class ModelA extends AppModel {
var $belongsTo = array('ModelB');
// i recently learn that this will raise "auto-recursive"
automatically, marvellous!
var $actsAs = array('Containable');
var $contain = array(
'ModelB' => array(
'order' => $nonexistentReference->ModelB->order
)
);
}
class ModelB extends AppModel {
var $hasMany = array('ModelA');
var $order = 'ModelB.modelb_column DESC';
}
i cannot centralize, in respective models, both ModelA contain and
ModelB order properties, cause it is not possible for models to have
references to each other...
if i decide to centralize ModelA contain i need to explicit define the
(external) order string:
class ModelA extends AppModel {
var $belongsTo = array('ModelB');
// i recently learn that this will raise "recursive" automatically ;)
var $actsAs = array('Containable');
var $contain = array(
'ModelB' => array(
'order' => 'ModelB.column DESC'
)
);
}
class ModelB extends AppModel {
var $hasMany = array('ModelA');
}
am i right?
(if so, i allow myselft to say that this is not awesome, cause i now
have a ModelB property set in the ModelA... correct me if i am wrong)
thanks again!
On Sep 26, 4:03 pm, brian <bally.z...@gmail.com> wrote:
> On Sat, Sep 26, 2009 at 9:38 AM, lorenx <lor...@gmail.com> wrote:
>
> > sorry...
>
> > and if i need something like this
>
> > 'contain' => array(
> > 'DpageStruct' => array(
> > 'DpageStructField' => array(
> > 'DpageField' => array(
> > 'Language'
> > ),
> > 'HtmlInputType',
> > 'order' => $this->OtherModel->order
> > )
> > )
> > )
>
> > is that the correct way to refer to the OtherModel property or not...
>
> Yes and no. You can refer to it as $this->OtherModel->order IF your
> model has a class var $order. But the order option shouldn't be inside
> your contain array, anyway.
>
> $this->YourModel->find(
> 'all',
> array(
> 'order' => $this->TheModel->order,
> 'contain' => $this->TheModel->contain
> )
> );
>
> Besides, even if you could put the 'order' option inside the 'contain'
> array, it still wouldn't work if you also want to use a class var
> $contain. ie, it wouldn't work because you can't do (in the model)
>
> var $order = array(...);
>
> var $contain = array(
> 'DpageStruct' => array(
> 'DpageStructField' => array(
> 'DpageField' => array(
> 'Language'
> ),
> 'HtmlInputType',
> 'order' => $this->order
> )
> )
> );
>
> That would trigger a fatal error because you're defining a class
> variable yet using the keyword $this, which is inappropriate (there's
> no instance of the model at this point).
--~--~---------~--~----~------------~-------~--~----~
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
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment