Subject: Having problem with has_many associations
Hi All,
Im in a middle of something and this weird stuff happening !!!
I have some models / tables all are working with belongs_to and has_one. but when I give has_many it doesn't work.
table structure
Users idfirstnamelastnameaddress
Shoesiduser_idcolorsizemake
class User extends ActiveRecord\Model { static $has_many = array(array('shoes'))
}
class Shoe extends ActiveRecord\Model { static $belongs_to = array(array('user'))}
when I tried access $users = User::all();foreach($users as $user) { echo $user->firstname.' '.$user->shoe->model.'<BR>';
I get a "Undefined Property" error
but if I change the has_many to has_one in the User model, I get 1 record
please help
Close this post I found the solution.
Can you share the solution for your situation please? I have a similar problem.
Many thanks.
(1-2/2)
June 27 2010
March 5, 2012
Subject: Having problem with has_many associations
Hi All,
Im in a middle of something and this weird stuff happening !!!
I have some models / tables all are working with belongs_to and has_one. but when I give has_many it doesn't work.
table structure
Users
id
firstname
lastname
address
Shoes
id
user_id
color
size
make
class User extends ActiveRecord\Model {
static $has_many = array(array('shoes'))
}
class Shoe extends ActiveRecord\Model {
static $belongs_to = array(array('user'))
}
when I tried access
$users = User::all();
foreach($users as $user) {
echo $user->firstname.' '.$user->shoe->model.'<BR>';
}
I get a "Undefined Property" error
but if I change the has_many to has_one in the User model, I get 1 record
please help