Beau Beauchamp Sun Oct 23 16:24:30 -0400 2011

Subject: Serialize not including self-referential associations

Not sure if this is a bug or if I'm doing it wrong. Here's the model:

class Org extends ActiveRecord\Model {

    static $table_name = 'orgs';
    static $primary_key = 'org_id';

    static $belongs_to = array(
        array('parent', 'class_name' => 'Org', 'foreign_key' => 'parent_id')
    );

    static $has_many = array(
        array('orgusers'),
        array('users', 'through' => 'orgusers')
    );

}

It works well but when I attempt to serialize the result, it will not serialize the parent property (association). Can someone tell me if this is a bug?

$org = new Org;
$options = array( ... some options ... );
$result = $org->find($org_id, $options);
$result->to_json(array( 'include' => array('parent') ));

This forum has been really dead lately. Any help is appreciated. :)


Ray Lim Tue Apr 30 17:25:01 -0400 2013

I have the same question. Was an answer given?

(1-1/1)