Hi, i have some beginner's questions (i'm using CakePHP for some days now) and i want to relate them to a practical example:
I have 3 Tables: Players, Clubs and Clubs_Players CREATE TABLE IF NOT EXISTS players( id INT(11) NOT NULL auto_increment, lastname VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)); CREATE TABLE IF NOT EXISTS clubs( id INT(11) NOT NULL auto_increment, name VARCHAR(255) NOT NULL UNIQUE, PRIMARY KEY(id)); CREATE TABLE IF NOT EXISTS clubs_players( id INT(11) NOT NULL auto_increment, player_id INT(11) NOT NULL, from_club_id INT(11) NULL, to_club_id INT(11) NULL, from_datetime datetime NOT NULL, to_datetime datetime NOT NULL default '9999-12-31 23:59:59', PRIMARY KEY(id)); I want to create models, controllers and views via console: 1.) Is it right that i cannot add the validation "isUnique" for the model via console, only manually after? 2.) Which attributes i actually i have to validate? Does it make sense p.e. to set the rule "numeric" to the id or i have to validate only attributes that actually would appear in the form for p.e. edit or add? 3.) Associations: Is it correct that i have to add only one association to the model ClubPlayers (btw. why it isn't called ClubsPlayers?) and none to Player or Club, cause a player can exists without a club and vice versa? 4.) Problem: Table "clubs_players": 2 foreign keys of same table: "clubs". I found a solution here: http://nsslive.net/2009/07/02/cakephp-models-multiple-columns-to-the-same-table/ but when i am using the auto-generated view (http://localhost/ clubs_players) i am getting following error "Unknown column 'FromClub.club_id' in 'on clause' ". My model looks like that: [code] var $belongsTo = array( 'Player' => array( 'className' => 'Player', 'foreignKey' => 'player_id', 'conditions' => '', 'fields' => '', 'order' => '' ), 'FromClub' => array( 'className' => 'Club', 'foreignKey' => false, 'conditions' => 'FromClub.club_id = ClubsPlayer.from_club_id', 'fields' => '', 'order' => '' ), 'ToClub' => array( 'className' => 'Club', 'foreignKey' => false, 'conditions' => 'ToClub.club_id = ClubsPlayer.to_club_id', 'fields' => '', 'order' => '' ) ); [/code] Sure i have to modify besided the model the query too, but where i do that? In the controller? My ClubsPlayersController is still empty or in views/clubs_players/index.ctp? In the last mentioned i don't see any possiblities... Anyway... I hope that somebody can help me :) Thanks a lot! I also ordered me a CakePHP development book, cause i am quite motivated to work with this framework! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. 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
