Monday, April 8, 2013

Associations within models with Multiple Foreign keys in table

Hi there,
 
I am currently working on my first cake project and I am starting with creating a menu builder.
 
The features I would like this menu builder to have is:

Multiple Menus
Each Menu can have multiple links
Each Link will have a single URL / Location.
Any URL can be used multiple times by different links.

If a URL / Location is to change then every related links (URL / Location) will change accordingly.
 
I am trying to keep this project within Cakes conventions. 

At the moment I have 3 tables for this project:

Menus: Is where I store everything to do with the menu. Menu name, styles, User Auth.

id | name | random data columns.....

Links: Is where I store all of the link information within each menu. This will contain details like link location / url, display order, name of the link, User Auth etc. It also contains 2 foreign keys 1 for the menu and 1 for the link url location.

id | menu_id | location_id | random data columns....

Locations: Is where I store url locations. I use This for ease of use if locations change and I want to quick edit the change to reflect in my links.

id | location | random data columns......


My models are associated as below:

Menu $hasMany='links';

Link $belongsTo=array('Menu'=> array(), 'location'=> array());

Location $hasmany='Links';


I hope what I I have described so far makes sense.

The problems I am having so far is that I would like to know what I am doing is keeping within Cakes conventions.
Also I would like to know how i would go about doing a Find() to return all of the menus with their links and locations. 

Would i do a find('all') on menu to get all data I need?
Or do i do a find('all') on link to get all of the data i need? 

From what I understand in the Cake documentation is if i did a Find('all') on with Menu model then using the associations i have setup it would. Display each link under each menu and each URL associated with each link.

For some reason it only returns menu's and their links but no URL's. I have tried to use the recursive value and changed it to 2 but this made no difference.

Thanks in Advance

Danny


 

--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: