Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need helper functions to map strait-forward properties #9

Open
enov opened this issue Nov 8, 2013 · 1 comment
Open

Need helper functions to map strait-forward properties #9

enov opened this issue Nov 8, 2013 · 1 comment

Comments

@enov
Copy link
Owner

enov commented Nov 8, 2013

Let's say we have a model that has lots of properties

    public function db_retrieve($model, array $row) {
        /* @var $model Model_Article */
        $tbl = Au::db()->table($this);
        $model->set_id($row[$tbl . '.id']);
        $model->set_name($row[$tbl . '.name']);
        $model->set_label($row[$tbl . '.label']);
        $model->set_description($row[$tbl . '.description']);
        $model->set_designation($row[$tbl . '.designation']);
        $model->set_weight($row[$tbl . '.weight']);
        // Delegate retrieving the row to Aurora_Brand
        $model->set_brand(
          Au::factory('Brand')
            ->db_retrieve(Model::factory('Brand'), $row)
        );
    }

Would it be nicer if we had a helper function to be used just for strait-forward mappings:

    public function db_retrieve($model, array $row) {
        $this->map_retrieve(
            $model,
            $row,
            ['id', 'name', 'label', 'description', 'designation', 'weight']
        );
        // Delegate retrieving the row to Aurora_Brand
        $model->set_brand(
          Au::factory('Brand')
            ->db_retrieve(Model::factory('Brand'), $row)
        );
    }
@enov enov closed this as completed Nov 11, 2013
@enov enov reopened this Nov 11, 2013
@enov
Copy link
Owner Author

enov commented Nov 11, 2013

I am implementing this as a Trait. It should be used inside Aurora.

I find myself making Auroras extend their Models to reach protected properties.

If I implement this as an external class, I will not be able to reach protected properties.

This will be PHP 5.4+ feature.

enov added a commit that referenced this issue Nov 11, 2013
enov added a commit that referenced this issue Nov 12, 2013
enov added a commit to enov/Aurora-QA that referenced this issue Nov 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant