When generating a table from this model:
function init()
{
parent::init();
$this->addField('person_id')->refModel('Model_Person')->mandatory(true);
$this->addField('username')->mandatory(true);
$this->addField('password')->mandatory(true);
}
I get this SQL statement:
create table users (
id int auto_increment not null primary key,
person_id varchar(255),
person int(11),
username varchar(255),
password varchar(255));
In this SQL statement i get the opposite of what is said in the tutorial:
Calling refModel with a field name ending in "_id" will actually create 2 field definitions. "publisher_id", for instance, will be defined as integer and will have type "reference", and a field "publisher" will also be added, with exactly same properties - but it will be a calculated field and will use sub-select to determine the value.
I want to know:
- Is the generated SQL statement correct?
- What does this VARCHAR additional generated field do? (I made CRUD and when added new records, the value of this field was saved as NULL).
- When using
refModel()
, if i used the model name only ('Person') i got an error (Unable to include Person.php), i had to use the complete class name ('Model_Person'). Is this ok? shouldn't i be able to use the model name only? - The
mandatory()
doesn't use NOT NULL, is there way to do this?