Niranjan Acharya Sun Dec 11 02:58:46 -0500 2011

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


Niranjan Acharya Sun Dec 11 04:55:57 -0500 2011

Close this post I found the solution.

Jon Warner Mon Dec 19 14:44:21 -0500 2011

Can you share the solution for your situation please? I have a similar problem.

Many thanks.

(1-2/2)