Aurora icon indicating copy to clipboard operation
Aurora copied to clipboard

Need helper functions to map strait-forward properties

Open enov opened this issue 12 years ago • 1 comments

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 avatar Nov 08 '13 17:11 enov

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 avatar Nov 11 '13 10:11 enov