1

I have 2 models: Home and User. A user can has many homes, and a home can have many users.

The table homes_users (the relation table) has these fields: User_id, home_id, date

I need to create a relation between the X user and the Y home, created in Z date (just a date) The code i'm using is:

$user = ORM::factory('User',$user_id);
$user->home_id = $home_id;
$user->date = date("Y-m-d");
$user->save();

But the system says "The property home_id doesn't exists in User_model"

I can add a home to a user, but i cant add a home to a user CREATED IN Z DATE.

How can i do that????

Theo
  • 87
  • 1
  • 10

1 Answers1

0

You will have to create a model for your pivot table, so you can check this question. Then in pivot model you will add: protected $_created_column = array('column' => 'date', 'format' => 'Y-m-d H:i:s'); where 'date' is your column name.

Community
  • 1
  • 1
dzeno
  • 510
  • 1
  • 5
  • 16
  • I have to create the Model for my Pivot table to use $user->add('home', $home, array('date' => time())); $home = ORM::factory('home', array('name' => 'user')); ??? – Theo Mar 04 '13 at 19:32
  • No, that is option where you do not have to create the model. For the first option you must create model, it is up to you to choose. – dzeno Mar 04 '13 at 19:48
  • Great, but i made a mistake, its a many-to-many relationship between user and home models. And maybe that code won't work anymore $user->add('home', $home, array('date' => time())); $home = ORM::factory('home', array('name' => 'user')); – Theo Mar 04 '13 at 20:13
  • I tried this: $user->add(ORM::factory('home',array("home_id"=>$home_id,"created" => date("Y-m-d")))); but doesn't work too – Theo Mar 04 '13 at 20:15
  • I'm using kohana 2.x, so the method ADD accepts just one parameter (a model). Is there any other solution? – Theo Mar 04 '13 at 21:20