Friday, January 31, 2014

CakePHP's naming conventions on hasMany through (The Join Model)

After struggling with this inconvenience for a couple of weeks now, I've decided to open en now topic here. A topic that can help me, but I'm sure it will help some others with this same problem too!

I wonder how I should name the tables, controllers and models of a hasMany through table (thus with additional fields) and it's coupled tables. I tried to stick on the CakePHP naming conventions as discribed in it's cookbook, but this constantly gave me some "Object not found" errors. For practical reason, I'll show you my problem with a many-words table. Perhaps that could be the reason of the problem? ;)

Situation

I have a fansite of a themepark and as you now, a themepark has many attractions. To ride an attraction, you must have a minimal height. Sometimes, small people can only ride it with an adult companion. But most of the time: you are allowed to ride the attraction because you just are tall enough ;)
Now I want to show the information of a specific attraction on my website. Name, content, photos, and so on. In addition to that information, I want to display my guests if they (or their kids) are tall enough to ride that attraction. It should appear like this way:

0m00 -> 1m00: not allowed
1m00 -> 1m30: allowed with an adult companion
1m30 -> 1m90: allowed

Database

I have two tables that are representing two objects: "attractions" & "attraction_accessibilities". In this case, I'm 100% sure the database names are correct. Secondly, I should have another table between "attractions" and "attraction_accessibilities". This table should contain:

  • an id specific for each record
  • a link to the id of the "attractions" table (attraction_id)
  • a link to the id of the "attraction_accessibilities" table (attraction_accessibility_id)
  • the additional information like "min-height" and "max-height"
I think I should name that table "attraction_accessibilities_attractions". It's a constriction of the two other tables, and I did it that way because CakePHP proposed it when you're making a HABTM association (http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasandbelongstomany-habtm).

But unfortunately, when I do call it that way, I've never succeeded to link those models in my application together.

Question

Is there anybody who've had the same problem but found a solution for it? If "yes": how should I name my database tables then and also important: how should I name my controller and model .php files?
Many thanks for the one who could help me and some other hopeless programmers ;)

--
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: