Re: About tabels relations in my models

2006-07-21 Thread AD7six

Hi Tuner,

This is a hasAndBelongsToMany relationship. You would need to name your
join table groups_users for things to be handled automatically (the
names need to be in alphabetical order), and the "id" field in the join
table wouldn't be used.

If the conventions are followed you can define this in your user model:
var $hasAndBelongsToMany = Array("Group");

And this in your Group model:
var $hasAndBelongsToMany = Array("User");

Just in case: It is not absolutely necessary to follow the convetions,
but if you donĀ“t you will need to tell Cake the things it would
otherwise know. See the section on "defining and querying
hasAndBelongsToMany here http://manual.cakephp.org/chapter/6 for more
details, or http://www.cakephp.org/search?q=hasAndBelongsToMany if you
find you still have more questions.

Cheers,

AD7six


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: About tabels relations in my models

2006-07-21 Thread davide
Tener wrote:
> I have 3 tables:
> 
> users:
> id | username | password
> 
> groups:
> id | groupname
> 
> user_groups:
> id | user_id | group_id
> 
> How to set members declarations (is that the proper-english-name for
> objects/classes variables?) of 3 models to make everything works
> perfectly?

I'm writing without a sample code by my hand, so I can make mistakes.

From the table you are showing it seems to be a hasAndBelongsToMany
relationship. A user can have many groups and a group can have many users.

So create the tables as the following

users: id, username, pass
groups: id, groupname
groups_users: group_id, user_id

From the cake naming conventions, the relation table name should be a
composite name of the two related table ordered by name.

Then it should be time for model

class User extends AppModel
   var $name = "User";
   var $hasAndBelongsToMany = "Group";

class Group extends AppModel
   var $name = "Group";
   var $hasAndBelongsToMany = "User";

HTH
bye
Davide






signature.asc
Description: OpenPGP digital signature


About tabels relations in my models

2006-07-21 Thread Tuner

Hello! I don't have much experience in CakePHP. I have read tutorials,
wiki and I have studied a lot of code of this framework but I have a
problem with one basic thing.

I have 3 tables:

users:
id | username | password

groups:
id | groupname

user_groups:
id | user_id | group_id

How to set members declarations (is that the proper-english-name for
objects/classes variables?) of 3 models to make everything works
perfectly?

Thx for your help,
Tuner

P.S. Sorry for my terrible english.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---