Property not found

I'm trying to build models using ORM in FuelPHP, never used ORM before, so not sure of certain aspects.

I have a table Project and a table Revision. Now, projects have multiple revisions, revision has only one project.

However, I have an additional link between Project and Revision where I always keep the ID of the latest revision in my Project table.

My tables look like this:

projects
- id
- latest_revision_id
- ...

revisions
- id
- project_id
- ...

The project model:

class Model_Project extends OrmModel
{

    protected static $_belongs_to = array(
        'latest_revision' => array(
            'key_from' => 'latest_revision_id'
        ),
    );

    protected static $_has_many = array(
    'revisions',
    );

...

}

The revision model:

class Model_Revision extends OrmModel
{

    protected static $_belongs_to = array(
        'project',
    );

    protected static $_has_one = array(
        'project' => array(
            'key_to' => 'latest_revision_id',
        ),
    );

}

However, when I try to access:

$project->latest_revision

It gives me an OutOfBoundException: OutOfBoundsException [ Error ]: Property "latest_revision_id" not found for Model_Project.

Am I missing something?

Thanks!


Looks like I had to add the latest_revision_id to my $_properties array. Which I swear I tried before posting the question, but guess I had another problem at the time!

So my project model now:

protected static $_belongs_to = array(
    'latest_revision' => array(
        'key_from' => 'latest_revision_id',
        'model_to' => 'Model_Revision',
    ),
);

protected static $_has_many = array(
    'revisions',
);

protected static $_properties = array(
    'id', 
    ..., 
    'latest_revision_id',
);
链接地址: http://www.djcxy.com/p/64804.html

上一篇: Fuelphp与orm一样的逻辑

下一篇: 未找到物业