Skip to content

Model finders can no longer be invoked from within an instance method. #851

@mikegreiling

Description

@mikegreiling

This bug was introduced in e73ffe6 (Issue #744)

Apparently, now that Model has both a __call() and __callStatic() method, when I attempt to invoke a finder from within an instance method of the model itself using the "syntactic magic" from Model's __callStatic(), it will go through the __call() method instead.

Example:

class Users extends \lithium\data\Model {
    public function getNext($entity, $token = null) {
        $conditions = [...];
        return static::first(compact('conditions'));
    }
}

It invokes Model::__call() instead of Model::__callStatic() and I get the exception Unhandled method call 'first'.

If I define it this way, it'll work... but it's not ideal, and the magic method used to work just fine.

class Users extends \lithium\data\Model {
    public function getNext($entity, $token = null) {
        $conditions = [...];
        return static::find('first',compact('conditions'));
    }
}

Related stackoverflow threads:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions