Re: simple "contain" question
sorry... i didn't explain it well at all! :P i meant this: if it is possible to set in the model file the "contain" array with all the details; 'contain' => array( 'DpageStruct' => array( 'DpageStructField' => array( 'DpageField' => array( 'Language' ), 'HtmlInputType' ) ) ) otherwise i have to repeat it in all the find() that need it... thanks. On Sep 25, 10:00 pm, brian wrote: > Do you mean that you only want that one model to implement it? Yes, > you can do that. The syntax is exactly the same as with AppModel: > > var $actsAs = array('Containable'); > > or (PHP5 only) > > public $actsAs = array('Containable'); > > > > On Fri, Sep 25, 2009 at 1:46 PM, lorenx wrote: > > > hi all. > > > is it possible to set the containable behaviour of a model in its > > model file? > > just to set it once, staticly... maybe with the ability to change it > > on the fly when needed... > > > thanks --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
var $contain = array(...); In controller: 'contain' => $this->YourModel->contain On Sat, Sep 26, 2009 at 5:50 AM, lorenx wrote: > > sorry... i didn't explain it well at all! :P > i meant this: if it is possible to set in the model file the "contain" > array with all the details; > > 'contain' => array( > 'DpageStruct' => array( > 'DpageStructField' => array( > 'DpageField' => array( > 'Language' > ), > 'HtmlInputType' > ) > ) > ) > > otherwise i have to repeat it in all the find() that need it... > > thanks. > > > > On Sep 25, 10:00 pm, brian wrote: >> Do you mean that you only want that one model to implement it? Yes, >> you can do that. The syntax is exactly the same as with AppModel: >> >> var $actsAs = array('Containable'); >> >> or (PHP5 only) >> >> public $actsAs = array('Containable'); >> >> >> >> On Fri, Sep 25, 2009 at 1:46 PM, lorenx wrote: >> >> > hi all. >> >> > is it possible to set the containable behaviour of a model in its >> > model file? >> > just to set it once, staticly... maybe with the ability to change it >> > on the fly when needed... >> >> > thanks > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
On Sat, Sep 26, 2009 at 10:36 AM, lorenx wrote: > > ok, just to make sure we understand each other :) > > 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! Yes, that's correct. But it's due to the limitations of OO programming, not Cake. In the class variable declarations, it's not possible to refer to other properties of the model because there's no instance of it yet. I suppose it's MAYBE possible to do: var $contain = array( 'ModelB' => array( 'order' => ClassRegistry::init('ModelB')->order ) ); ... but I'm not sure I even want to know. That looks dreadful. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
ok, i follow your advice and i stop here. thank a lot, really! On Sep 26, 4:45 pm, brian wrote: > On Sat, Sep 26, 2009 at 10:36 AM, lorenx wrote: > > > ok, just to make sure we understand each other :) > > > 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! > > Yes, that's correct. But it's due to the limitations of OO > programming, not Cake. In the class variable declarations, it's not > possible to refer to other properties of the model because there's no > instance of it yet. > > I suppose it's MAYBE possible to do: > > var $contain = array( > 'ModelB' => array( > 'order' => ClassRegistry::init('ModelB')->order > ) > ); > > ... but I'm not sure I even want to know. That looks dreadful. --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
ok, just to make sure we understand each other :) 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 wrote: > On Sat, Sep 26, 2009 at 9:38 AM, lorenx 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
On Sat, Sep 26, 2009 at 10:03 AM, brian wrote: > On Sat, Sep 26, 2009 at 9:38 AM, lorenx 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). > Wait. Cancel that. You can, in fact, use 'order' within the 'contain' array. But my last comment stands. You couldn't refer to a class var $order while defining the class var $contain. Unless you think you'll need to refer to $this->TheModel->order somewhere, you're probably better off not declaring it and just spell out the order in the declaration for $contain because you'd be defining it twice. ie: var $order = array('foo' => 'bar'); var $contain = array( 'DpageStruct' => array( 'DpageStructField' => array( 'DpageField' => array( 'Language' ), 'HtmlInputType', 'order' => array('foo' => 'bar') ) ) ); That doesn't seem very efficient. Does that make sense? --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
No, the behavior wouldn't automatically pick it up. Also, it accepts only 3 options ('recursive', 'notices', 'autoFields'), so you couldn't pass the array like this: var $actsAs = array( 'Containable' => array( 'DpageStruct' => array( 'DpageStructField' => array( 'DpageField' => array( 'Language' ), 'HtmlInputType' ) ) ) ); Although, that would be handy. Perhaps there's a good reason for that but I'm barely into my first coffee so I can't say. On Sat, Sep 26, 2009 at 9:32 AM, lorenx wrote: > > ...and so > 'contain' => $this->YourModel->contain > is not automatic... > > i guess that > var $order > setting has the same behaviour... > > thanks a lot. > > > > On Sep 26, 3:27 pm, brian wrote: >> var $contain = array(...); >> >> In controller: >> >> 'contain' => $this->YourModel->contain >> >> >> >> On Sat, Sep 26, 2009 at 5:50 AM, lorenx wrote: >> >> > sorry... i didn't explain it well at all! :P >> > i meant this: if it is possible to set in the model file the "contain" >> > array with all the details; >> >> > 'contain' => array( >> > 'DpageStruct' => array( >> > 'DpageStructField' => array( >> > 'DpageField' => array( >> > 'Language' >> > ), >> > 'HtmlInputType' >> > ) >> > ) >> > ) >> >> > otherwise i have to repeat it in all the find() that need it... >> >> > thanks. >> >> > On Sep 25, 10:00 pm, brian wrote: >> >> Do you mean that you only want that one model to implement it? Yes, >> >> you can do that. The syntax is exactly the same as with AppModel: >> >> >> var $actsAs = array('Containable'); >> >> >> or (PHP5 only) >> >> >> public $actsAs = array('Containable'); >> >> >> On Fri, Sep 25, 2009 at 1:46 PM, lorenx wrote: >> >> >> > hi all. >> >> >> > is it possible to set the containable behaviour of a model in its >> >> > model file? >> >> > just to set it once, staticly... maybe with the ability to change it >> >> > on the fly when needed... >> >> >> > thanks > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
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... On Sep 26, 3:32 pm, lorenx wrote: > ...and so > 'contain' => $this->YourModel->contain > is not automatic... > > i guess that > var $order > setting has the same behaviour... > > thanks a lot. > > On Sep 26, 3:27 pm, brian wrote: > > > > > var $contain = array(...); > > > In controller: > > > 'contain' => $this->YourModel->contain > > > On Sat, Sep 26, 2009 at 5:50 AM, lorenx wrote: > > > > sorry... i didn't explain it well at all! :P > > > i meant this: if it is possible to set in the model file the "contain" > > > array with all the details; > > > > 'contain' => array( > > > 'DpageStruct' => array( > > > 'DpageStructField' => array( > > > 'DpageField' => array( > > > 'Language' > > > ), > > > 'HtmlInputType' > > > ) > > > ) > > > ) > > > > otherwise i have to repeat it in all the find() that need it... > > > > thanks. > > > > On Sep 25, 10:00 pm, brian wrote: > > >> Do you mean that you only want that one model to implement it? Yes, > > >> you can do that. The syntax is exactly the same as with AppModel: > > > >> var $actsAs = array('Containable'); > > > >> or (PHP5 only) > > > >> public $actsAs = array('Containable'); > > > >> On Fri, Sep 25, 2009 at 1:46 PM, lorenx wrote: > > > >> > hi all. > > > >> > is it possible to set the containable behaviour of a model in its > > >> > model file? > > >> > just to set it once, staticly... maybe with the ability to change it > > >> > on the fly when needed... > > > >> > thanks --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
On Sat, Sep 26, 2009 at 9:38 AM, lorenx 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
...and so 'contain' => $this->YourModel->contain is not automatic... i guess that var $order setting has the same behaviour... thanks a lot. On Sep 26, 3:27 pm, brian wrote: > var $contain = array(...); > > In controller: > > 'contain' => $this->YourModel->contain > > > > On Sat, Sep 26, 2009 at 5:50 AM, lorenx wrote: > > > sorry... i didn't explain it well at all! :P > > i meant this: if it is possible to set in the model file the "contain" > > array with all the details; > > > 'contain' => array( > > 'DpageStruct' => array( > > 'DpageStructField' => array( > > 'DpageField' => array( > > 'Language' > > ), > > 'HtmlInputType' > > ) > > ) > > ) > > > otherwise i have to repeat it in all the find() that need it... > > > thanks. > > > On Sep 25, 10:00 pm, brian wrote: > >> Do you mean that you only want that one model to implement it? Yes, > >> you can do that. The syntax is exactly the same as with AppModel: > > >> var $actsAs = array('Containable'); > > >> or (PHP5 only) > > >> public $actsAs = array('Containable'); > > >> On Fri, Sep 25, 2009 at 1:46 PM, lorenx wrote: > > >> > hi all. > > >> > is it possible to set the containable behaviour of a model in its > >> > model file? > >> > just to set it once, staticly... maybe with the ability to change it > >> > on the fly when needed... > > >> > thanks --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: simple "contain" question
Do you mean that you only want that one model to implement it? Yes, you can do that. The syntax is exactly the same as with AppModel: var $actsAs = array('Containable'); or (PHP5 only) public $actsAs = array('Containable'); On Fri, Sep 25, 2009 at 1:46 PM, lorenx wrote: > > hi all. > > is it possible to set the containable behaviour of a model in its > model file? > just to set it once, staticly... maybe with the ability to change it > on the fly when needed... > > thanks > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
simple "contain" question
hi all. is it possible to set the containable behaviour of a model in its model file? just to set it once, staticly... maybe with the ability to change it on the fly when needed... thanks --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---