fuel / orm

Fuel PHP Framework - Fuel v1.x ORM
http://fuelphp.com/docs/packages/orm/intro.html
152 stars 96 forks source link

Fix on to_array with multi level relations #359

Closed ltoussaint closed 10 years ago

ltoussaint commented 10 years ago

First, I fixed a problem in to_array method when having _hasmany relation with a target class having a _hasone relation.

When having relations like

School  -has_many-> School_Class_1 -has_one-> School_Class_1_Info
                    School_Class_2 -has_one-> School_Class_2_Info
                    School_Class_3 -has_one-> School_Class_3_Info

The to_array method only inject the first instance of School_Class_Info. So I get array like

school => array(
    ...
    school_class_1 => array(
        ...
        school_class_1_info => array(...)
    ),
    school_class_2 => array(...), // Without school_class_2_info
    school_class_3 => array(...), // Without school_class_3_info
)

In a second commit, I add circular reference check on _hasmany relation

Logically this case should not happen with a good data model, but if we want to check circular references, we need to do it in all cases.

WanWizard commented 10 years ago

@stevewest looks ok?

emlynwest commented 10 years ago

Yea, looks ok to me.