On Tue, Jan 6, 2009 at 7:05 PM, The_Saint <[email protected]> wrote: > > Let me give an example. > I have a User table, a sponsor table and a permission table > Not every user is a sponsor. But every sponsor is a user. > So this looks like: > > USERS > id (INT) > sponsor_id (INT) > permission_id (INT) > > SPONSORS > id (INT) > > PERMISSIONS > id (INT) > > Do I just set up "Sponsors hasmany users (foreign key being > sponsor_id)" > or is it the other way around?
It looks to me like you should have USERS id SPONSORS id user_id PERMISSIONS id user_id Sponsor belongsTo User Permission belongsTo User If not all Users may be a Sponsor, you certainly don't want to have User.sponsor_id. If a User may have more than 1 Permission, then you'd need a HABTM join table: permissions_users: permission_id user_id > One general question. Have a couple of other tables. and fill a > tinyint in the user table if there is a record relating to the user in > some of those tables. > I used to do that to just speed things up in my old way of > programming. So I didn't have to make a joint SQL statement to look it > up in one php page and then show a new page and doing the joint again. > if the tinyint was ticked I make a link and have the other page do the > joint statement to show the result. Else the link wasn't there. > "select has_thing from user" is quicker than writing out the full > joint statement. > Is CakePHP always making the joint connections when doing the view, or > can I still do it the same way and have less calls to the database? I'm not sure that I follow. One thing you should be looking at is how the DB does its query planning whether you use proper joins or the method you describe. I'd think you'd be best off just creating the associations. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
