What happens if you add a $hasMany Place statement to the Thing model?

Jeremy Burns
Class Outfit

[email protected]
http://www.classoutfit.com

On 24 Feb 2011, at 05:44, Ryan Schmidt wrote:

> I'm using CakePHP 1.3.6 and am trying to use Containable for the first time, 
> and I have an index action (as CakePHP baked it for me) that uses paginate().
> 
> Since I suspect I will want to use Containable everywhere, in my 
> app_model.php I have:
> 
> class AppModel extends Model {
>    var $actsAs = array('Containable');
> ...
> }
> 
> I have models Thing and Place, and Thing has relationships with up to two 
> places. In models/thing.php I have:
> 
> class Thing extends AppModel {
>    var $belongsTo = array(
>        'Place' => array(
>            'className' => 'Place',
>            'foreignKey' => 'place_id',
>        ),
>        'CurrentPlace' => array(
>            'className' => 'Place',
>            'foreignKey' => 'current_place_id',
>        ),
>    );
> ...
> }
> 
> The idea is that I need to keep track of where this Thing is now 
> (CurrentPlace) and allow the user to specify where they want it to be some 
> time later (Place). Either of these Places could also be empty / null.
> 
> In models/place.php I don't have any relationships defined about Things (do I 
> need to?)
> 
> In controllers/things_controller.php I have:
> 
> class ThingsController extends AppController {
>    function admin_index() {
>        $this->paginate = array(
>            'fields' => array(
>                'Thing.id',
>                'Thing.name',
>                'Thing.created',
>                'Thing.modified',
>            ),
>            'contain' => array(
>                'Place.name',
>                'CurrentPlace.name',
>            ),
>        );
>        $this->set('things', $this->paginate());
>    }
> ...
> }
> 
> When I view the index, I get:
> 
> Notice (8): Trying to get property of non-object 
> [CORE/cake/libs/model/behaviors/containable.php, line 408]
> 
> This goes away if I remove the 'contain' array entry about CurrentPlace. So 
> it seems to not like it when I use a relationship name that is not also a 
> model name.
> 
> Am I doing something wrong? Any idea what I should do to fix it? Thanks.
> 
> 
> 
> 
> 
> -- 
> Our newest site for the community: CakePHP Video Tutorials 
> http://tv.cakephp.org 
> Check out the new CakePHP Questions site http://ask.cakephp.org and help 
> others with their CakePHP related questions.
> 
> 
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to