Answer the question
In order to leave comments, you need to log in
ORM in Kohana 3.1?
The scheme is rather non-trivial, and I cannot translate it into ORM. Writing through the Query Builder will not work, since you will have to shovel hundreds of lines with ORM objects.
The Owner field refers to the Auth module's users table, if you're interested.
The problem is in three fields of the events table that refer to the PRIMARY KEY of the days table. How to describe them? Constantly pops up an error when trying to write.
Here are the models without the damn margins:
class Model_Event extends ORM {<br/>
protected $_table_columns = array(<br/>
'id' => array('data_type' => 'int', 'is_nullable' => FALSE),<br/>
'owner' => array('data_type' => 'int', 'is_nullable' => FALSE),<br/>
'name' => array('data_type' => 'tinytext', 'is_nullable' => FALSE),<br/>
'starting_time' => array('data_type' => 'time', 'is_nullable' => FALSE),<br/>
'ending_time' => array('data_type' => 'time', 'is_nullable' => FALSE),<br/>
'place' => array('data_type' => 'tinytext', 'is_nullable' => FALSE),<br/>
'person_in_charge' => array('data_type' => 'tinytext'),<br/>
'seats' => array('data_type' => 'int'),<br/>
'info' => array('data_type' => 'mediumtext'),<br/>
'program' => array('data_type' => 'mediumblob'),<br/>
'verified' => array('data_type' => 'bool'),<br/>
);<br/>
protected $_has_many = array(<br/>
'owner' => array(<br/>
'model' => 'user',<br/>
'foreign_key' => 'owner')<br/>
);<br/>
};
class Model_Day extends ORM {<br/>
protected $_table_columns = array(<br/>
'day' => array('data_type' => 'date', 'is_nullable' => FALSE),<br/>
'max_events' => array('data_type' => 'int', 'is_nullable' => FALSE, 'default' => 10),<br/>
);<br/>
protected $_primary_key = 'day';<br/>
};<br/>
$event->values(Arr::extract($_POST, array('name','starting_time','ending_time','place','person_in_charge','seats','info'), NULL));<br/>
$event->owner = Auth::instance()->get_user()->id;<br/>
$starting_day = new Model_Day;<br/>
$ending_day = new Model_Day;<br/>
$starting_day -> day = Request::current()->post('starting_day');<br/>
$ending_day -> day = Request::current()->post('ending_day');<br/>
$opened_until = new Model_Day;<br/>
$opened_until -> day = Request::current()->post('opened_until');<br/>
if (!($starting_day->find())) $starting_day -> create();<br/>
if (!($ending_day->find())) $ending_day -> create();<br/>
if (!($opened_until->find())) $opened_until -> create();<br/>
$event->add('starting_day',$starting_day);<br/>
$event->add('ending_day',$ending_day);<br/>
$event->add('opened_until', $opened_until);<br/>
$event->create();<br/>
$event->add('starting_day',$starting_day);
, which is typical.
Answer the question
In order to leave comments, you need to log in
The add() method only works for ManyToMany relationships. For singly related fields (HasOne, BelongsTo) you should use something like $event->starting_day = $starting_day
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question