pomm-project / ModelManager

Model Manager for the Pomm database framework.
MIT License
66 stars 27 forks source link

Wrong method invocation for magic methods in FlexibleEntity #50

Closed yann-eugone closed 8 years ago

yann-eugone commented 8 years ago

Hi all,

I'm facing a weird issue with my tests of Pomm ModelManager, integrated to Symfony.

I defined my models (from an existing database structure), queried my database, and got my objects back. But when I try to use the objects (originaly using Twig, but i get the same error by querying isset($object->property)) I'm facing this issue :

PommProject\ModelManager\Exception\ModelException No such key 'hastitle'.

Here is the stack trace :

at FlexibleEntity ->get ('hastitle') vendor/pomm-project/model-manager/sources/lib/Model/FlexibleEntity.php at line 172
at FlexibleEntity ->__call ('getHastitle', array()) in vendor/pomm-project/model-manager/sources/lib/Model/FlexibleEntity.php at line 307  
at Post ->getHastitle () in vendor/pomm-project/model-manager/sources/lib/Model/FlexibleEntity.php    
at line 307   
at FlexibleEntity ->__get ('hasTitle') in vendor/pomm-project/model-manager/sources/lib/Model/FlexibleEntity.php at line 323   
at FlexibleEntity ->__isset ('title') in src/AppBundle/Controller/Blog/PostController.php at line 41   

Taking a look to the __isset method of FlexibleEntity you can see the following :

    public function __isset($var)
    {
        $method_name = "has".Inflector::studlyCaps($var);

        return $this->$method_name;
    }

To me, the problem is that the call parenthesis are missing, the method should be :

    public function __isset($var)
    {
        $method_name = "has".Inflector::studlyCaps($var);

        return $this->$method_name();
    }

And the problem may be the same in the __unset method, so :

    public function __unset($var)
    {
        $method_name = "clear".Inflector::studlyCaps($var);

        return $this->$method_name();
    }

I tried to fork the project, and create some tests. Unfortunately, Im' not very familiar with Atoum, and I got some problem running the test suite itself, so...

stood commented 8 years ago

You use PommBundle ?

Plz see your code Controller

yann-eugone commented 8 years ago

Yes, I use PommBundle, but I believe that the Bundle is not involved in the issue.

Here is the test code i use in the controller :

$posts = $this->getModel()->findAllPaginated(
    $request->query->get('limit', 10),
    $request->query->get('page', 1)
);

$iterator = $posts->getIterator();
$post = $iterator->current();
var_dump(isset($post->title));
chanmix51 commented 8 years ago

Good catch, thank you :+1: