Multiple associations per model

2007-12-28 Thread DaveM

Hi all,

I'm struggling with designing the models for an application I'm
building.  Here is my database structure:

players
-- id
-- name

games
-- id
-- player_one_id
-- player_two_id
-- player_three_id
-- player_four_id
-- player_five_id

Each game has five players.  Any player can appear in multiple games,
but not in the same game twice.  How would I need to setup my model
associations and how do I define the player_#_id fields in the game
views?

Thanks in advance!

Dave

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---



Re: Multiple associations per model

2007-12-28 Thread Ron Chaplin
Hey Dave,

It seems to me that a players table, a games table and a players_games
table would be in order here.

players
id

games
id

players_games
player_id
game_id

Then in your player model perhaps, check for uniqueness against games_id
I use this method in my user table to check for unique username

class User extends AppModel {

var $name = 'User';
var $actsAs = array( 'Acl'='requester' );
var $displayField = 'username';
var $validate = array(
'id' = array(
'rule' = 'blank',
'on' = 'create'
), 
'username' = array(
'checkUnique' = array(
'rule' = array('checkUnique', 'username'),
'message' = 'An account with that username has already
been registered.',
'on' = 'create'
)
),

.

function checkUnique($data, $fieldName) {
$valid = false;
if(isset($fieldName)  $this-hasField($fieldName))
{
$valid = $this-isUnique(array($fieldName = $data));
}
return $valid;
}


HTH
On Fri, 2007-12-28 at 16:52 -0800, DaveM wrote:

 Hi all,
 
 I'm struggling with designing the models for an application I'm
 building.  Here is my database structure:
 
 players
 -- id
 -- name
 
 games
 -- id
 -- player_one_id
 -- player_two_id
 -- player_three_id
 -- player_four_id
 -- player_five_id
 
 Each game has five players.  Any player can appear in multiple games,
 but not in the same game twice.  How would I need to setup my model
 associations and how do I define the player_#_id fields in the game
 views?
 
 Thanks in advance!
 
 Dave
 
  

Thanks,

Ronald Chaplin
Owner - T73 Software and Designs




  http://t73-softdesign.com/

  We'll Make All Of Your Wildest

e-Commerce Dreams Come True!

--~--~-~--~~~---~--~~
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?hl=en
-~--~~~~--~~--~--~---