Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Loading a Model's 'parent'
  • I am using ORM to relate my models. I have successfully set up the _has_one relation, but have a question on the _belongs_to relation. If I have a Model_Parent that _has_many Model_Child(ren)
    and, of course, a Model_Child that _belogs_to a Model_Parent and I $child = Model_Child::find('first') How do I access the Model_Parent information from $child? Do I have to load from the highest level? (aka, load Model_Parent?) The docs don't provide an example of how to access _beongs_to info: http://docs.fuelphp.com/packages/orm/relations/belongs_to.html Thanks in advance,
    Loving FuelPHP!
    David
  • You can access the parent by $child->parent
  • That's what I expected, not happening: <code>
    class Model_Journey extends \Orm\Model
    {
    protected static $_has_many = array(
    'events' => array(
    'key_from' => 'id',
    'model_to' => 'Model_Event',
    'key_to' => 'journey',
    'cascade_save' => false,
    'cascade_delete' => false,
    )
    );
    ...
    class Model_Event extends \Orm\Model
    {
    protected static $_belongs_to = array(
    'theJourney`' => array(
    'key_from' => 'journey',
    'model_to' => 'Model_Journey',
    'key_to' => 'id',
    'cascade_save' => false,
    'cascade_delete' => false,
    )
    );
    ... $event = Model_Event::find('all'); echo $event->theJourney; //OutOfBoundsException [ Error ]: Property "theJourney" is not found for Model_Event.
    </code> I've tried several combinations of different keys for the associative array with no luck. Passing the relation in the find('first', array('theJourney')) always errors as well with a relation not found error. Am stuck, suspect typo, can't see forest through trees... Thanks,
    David
  • I am not an expert at FuelPHP, using it for two weeks now, but I think you have to add the property to the properties array. Can you post the full models and a SQL layout of your tables?
  • Afaik relations should not be in the properties array, that's for table columns only. I would more go for an error in the relationship definition, that will cause the property not to be created.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion