0

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 Orm\Model
{

    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 \Orm\Model
{

    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!

4

1 回答 1

1

看起来我必须将 latest_revision_id 添加到我的 $_properties 数组中。我发誓我在发布问题之前尝试过,但我想我当时还有另一个问题!

所以我现在的项目模型:

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',
);
于 2012-07-03T12:36:11.350 回答