Tuesday, January 21, 2014

hasMany through: my neverending problem?

I have two tables: "attractions" & "accessibilities". I want to display which people can go on which rides so I invented a new, joined table called "accessibilities_attractions". Here's a visual representation of it:

Data in table "attraction" (id - name) can be:

1 - Rollercoaster name
2 - Big Rollercoaster name
3 - Realy Big Rollercoaster name
4 - Biggest Rollercoaster ever seen name

Table "accessibilities" (id - name) has exactly 3 records:

1 - Forbidden
2 - Accessible with supervisor
3 - Accessible

Data in "accessibilities_attractions" (accessibility_id - attraction_id - min - max) can be:

Forbidden - Big Rollercoaster name - null - 110
Accessible with supervisor - Big Rollercoaster name - 110 - 130
Accessibile - Big Rollercoaster name - 130 - null
Forbidden - Biggest Rollercoaster ever seen name - Forbidden - null - 140
Accessibile - Biggest Rollercoaster ever seen name - 140 - null

As I am developping a CMS system, I've made a plugin called "CoasterCMS". By this way, I implement a whole CMS system to CRUD the website elements of my favourite theme park (e.g. attractions, animals, events, ...)

To go further, I've created three models:

Accessibility.php

<?php

class Accessibility extends CoasterCmsAppModel
{
    public $hasMany = array(
        'CoasterCms.AccessibilityAttraction'
    );
}

Attraction.php

class Attraction extends CoasterCmsAppModel
{
...
    public $hasMany = array(
        'CoasterCms.AccessibilityAttraction'
    );
...
}

AccessibilityAttraction.php

<?php

class AccessibilityAttraction extends CoasterCmsAppModel
{
    public $belongsTo = array(
        'CoasterCms.Accessibility', 'CoasterCms.Attraction'
    );
}

Now, I've created a model so I can insert, change and delete records in table "accessibilities_attractions":

AccessibilitiesAttractionsController.php

<?php

class AccessibilitiesAttractionsController extends CoasterCmsAppController
{
    public $helpers = array('Html', 'Form', 'Session');
    public $components = array('Session');
    
    public function index()
    {
        debug($this->AccessibilityAttraction->find('all'));
    }
...
}

And that's the point where my problem comes in. Every time I try to get the records via the find('all') method in my index action, I'm not getting an object at all:

Error: Call to a member function find() on a non-object
File: D:\Websites\BellewaerdeFun 2014\03 - Online\app\Plugin\CoasterCms\Controller\AccessibilitiesAttractionsController.php
Line: 10

I realy don't understand what goes wrong, because I ordered myself to stick on the CakePHP name conventions so nothing can go wrong...
Can anyone see what I'm doing wrong? After 2 days of searching, I cannot povide the solution on my own...

Thanks in advance :)

--
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 unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: