I might as well continue this thread since there is relevant info here.
I am starting a project with a complex (for me) relational database, I want to generate the models and crud skeleton with the yiic tool. Here is an example of three tables that relate.
-- a table for different credit card types
CREATE TABLE IF NOT EXISTS `card_type` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;
-- a table for participant info
CREATE TABLE IF NOT EXISTS `participant` (
`id` int(11) NOT NULL auto_increment,
...
...
...
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;
-- a table for unique credit card info
CREATE TABLE IF NOT EXISTS `participant_credit_card` (
`id` int(11) NOT NULL auto_increment,
`participant_id` int(11) default NULL,
`card_type_id` int(11) default NULL,
`card_number` varchar(50),
`card_expiry` date NOT NULL default '0000-00-00',
FOREIGN KEY (participant_id) REFERENCES participant(id),
FOREIGN KEY (card_type_id) REFERENCES card_type(id),
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;
Using yiic tool I generate a model for participant like this
>>model participant
this creates the file participant.php under protected/models/
here is the relations part of that file
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'donations' => array(self::HAS_MANY, 'Donation', 'participant_id'),
'event_participants' => array(self::HAS_MANY, 'EventParticipant', 'participant_id'),
'events' => array(self::HAS_MANY, 'Events', 'contact_id'),
'gender' => array(self::BELONGS_TO, 'Gender', 'gender_id'),
'participant_credit_cards' => array(self::HAS_MANY, 'ParticipantCreditCard', 'participant_id'),
'participant_food_healths' => array(self::HAS_MANY, 'ParticipantFoodHealth', 'participant_id'),
'participant_participant_levels' => array(self::HAS_MANY, 'ParticipantParticipantLevel', 'participant_id'),
'participant_programs' => array(self::HAS_MANY, 'ParticipantProgram', 'participant_id'),
);
}
the relevant part of my question is in this line
'participant_credit_cards' => array(self::HAS_MANY, 'ParticipantCreditCard', 'participant_id'),
notice participant_credit_card is now ‘ParticipantCreditCard’ this is expected based on discussion previously in this thread.
creating the model for participant_credit_card (table name) in yiic I type
>>model participant_credit_card
this creates the file participant_credit_card.php under /protected/models
the class created in this file is class participant_credit_card
class participant_credit_card extends CActiveRecord
{
/**
* The followings are the available columns in table 'participant_credit_card':
* @var integer $id
* @var integer $participant_id
* @var integer $card_type_id
* @var string $card_number
* @var string $card_expiry
*/
do I have to change the class name to particpantCreditCard ? and/or the model filename?
I know the naming conventions are important but I am confused a class named participant_credit_card it seems to me that it should be changed to particpantCreditCard and ParticipantCreditCard.php
any advice would be much appreciated
doodle