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

[2.0.0] ORM enhancement #2790

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
2 participants
@ogarbe
Copy link
Contributor

commented Sep 6, 2014

ORM enhancements :

  • Replace new builder by models manager createBuilder call on model queries
  • Late state binding on hydration (cloneResultMap call) to be able to override class creation (refs #2786) - also done here for 1.3.3 : link to #2789

With this we can override the instantiation of an object to mimic Doctrine inheritance (http://the-phpjs-ldc.rgou.net/symfony1/more-with-symfony/en/09-Doctrine-Form-Inheritance.markdown)

/**
     * Assigns values to a model inherited class from an array returning a new model.
     *
     * @param \Phalcon\Mvc\Model $base          object to hydrate
     * @param array              $data          data to use for hydration
     * @param array              $columnMap     column mapping
     * @param int                $dirtyState    object state
     * @param boolean            $keepSnapshots keep snapshot
     *
     * @return \Phalcon\Mvc\Model
     */
    public static function cloneResultMap(
        $base,
        $data,
        $columnMap,
        $dirtyState = null,
        $keepSnapshots = null
    ) {
        if (isset($data['columnUsedForTableInheritance'])) {
            $class = '\Ournamespace\Models\\' . $data['columnUsedForTableInheritance'];
            if (class_exists($class)) {
                $base = new $class();
            }
        }
        return parent::cloneResultMap(
            $base,
            $data,
            $columnMap,
            $dirtyState,
            $keepSnapshots
        );
    }

@ogarbe ogarbe changed the title Inject Builder from ModelsManager in Models Inject Builder from ModelsManager in Models 2.0 Sep 6, 2014

@ogarbe ogarbe changed the title Inject Builder from ModelsManager in Models 2.0 [2.0.0] Inject Builder from ModelsManager in Models Sep 6, 2014

@ogarbe ogarbe force-pushed the vpg:2.0.0 branch from d43a0a7 to 4415961 Sep 6, 2014

@ogarbe ogarbe changed the title [2.0.0] Inject Builder from ModelsManager in Models [2.0.0] ORM enhancement Sep 6, 2014

@ogarbe ogarbe force-pushed the vpg:2.0.0 branch from 4415961 to cfb15bd Sep 8, 2014

@ogarbe

This comment has been minimized.

Copy link
Contributor Author

commented Sep 23, 2014

@boedy : can you give me an example where it doesn't work ?

Thanks

@boedy

This comment has been minimized.

Copy link

commented Sep 23, 2014

Sorry, it does work. I forgot to remove my comment here. I wrote up an bigger example in your forum post.

http://forum.phalconphp.com/discussion/3108/mimic-doctrine-table-inheritance

@ogarbe

This comment has been minimized.

Copy link
Contributor Author

commented Oct 9, 2014

Commit rebased + fix indentation

@ogarbe ogarbe force-pushed the vpg:2.0.0 branch from 53a63d9 to 5609df9 Oct 18, 2014

@ogarbe

This comment has been minimized.

Copy link
Contributor Author

commented Oct 28, 2014

@phalcon : any news on this PR ?

@ogarbe ogarbe force-pushed the vpg:2.0.0 branch from 5609df9 to fde0db1 Nov 2, 2014

@ogarbe

This comment has been minimized.

Copy link
Contributor Author

commented Nov 6, 2014

@andresgutierrez any update on this please ?

@ogarbe ogarbe force-pushed the vpg:2.0.0 branch from fde0db1 to fea0e8d Nov 14, 2014

@ogarbe ogarbe closed this Dec 7, 2014

@ogarbe

This comment has been minimized.

Copy link
Contributor Author

commented Dec 7, 2014

Reopened here : #3107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.