safrazik / breeze.server.php

Breeze JS support for PHP applications
MIT License
29 stars 11 forks source link

cannot execute _executeQueryCore until metadataStore is populated #8

Closed organic-scholar closed 9 years ago

organic-scholar commented 9 years ago

manager.executeQuery(query) promise failed with this error

safrazik commented 9 years ago

Can you give more insights on this issue please? What setup you are using, which version of breeze js you are using, how you create the manager object, etc. It would be better if you could share some sample code.

Also, please take a moment to read Ward's Answer to this StackOverflow question

organic-scholar commented 9 years ago

I am using symfony 2.5 with AdrotechWebApiBundle. Breeze js version is 1.4.17 metadata version 1.0.5 manager = new breeze.EntityManager('/api'); query = breeze.EntityQuery.from('User').orderBy('username');

manager.executeQuery(query).then(
    function(result){
        console.log(result);
    },
    function(error){
        console.log(error);
    }
);

Server is responding with metadata here it is

{ "metadata_version": "1.0.5", "structural_types": [ { "short_name": "User", "namespace": "CloudX.Bundle.MainBundle.Entity", "auto_generated_key_type": "Identity", "default_resource_name": "Users", "data_properties": [ { "name": "id", "data_type": "Int32", "is_nullable": false, "is_part_of_key": true }, { "name": "username", "data_type": "String", "is_nullable": false, "max_length": 30 }, { "name": "password", "data_type": "String", "is_nullable": false, "max_length": 30 } ] } ], "resource_entity_type_map": { "Users": "User:#CloudX.Bundle.MainBundle.Entity" } }

safrazik commented 9 years ago

Issue 1

I think JMSSerializerBundle is not registered in the right order in AppKernel.php. Please make sure you have the following lines in your bundles config and then clear the cache $ php app/console cache:clear

// ...
new JMS\SerializerBundle\JMSSerializerBundle(),
new Adrotec\WebApiBundle\AdrotecWebApiBundle(),
// ...

The order is important here because AdrotecWebApiBundle overrides some of the JMSSerializerBundle behaviours. E.g: it should be "shortName" instead of "short_name"

Issue 2

When you create breeze queries, you should refer to resourceName instead of shortName.

breeze.EntityQuery.from('Users') // not 'User'

to avoid this confusion, the library also supports resourceName to be the same as shortName (At Adrotec we follow this convention which works great for us)

        $app = $this->container->get('adrotec_webapi');

        $app->addResources(array(
            // 'ResourceName' => 'EntityFullyQualifiedClassName'
            'User' => 'CloudX\Bundle\MainBundle\Entity\User',
            // ...
        ));
breeze.EntityQuery.from('User') // now 'User' is the resourceName
organic-scholar commented 9 years ago

Thanks you. Yes JMSSerializerBundle is not registered in correct order. Now it is not giving error. You should mention it in docs.

safrazik commented 9 years ago

Yes thank you. We will update the documentation as per your suggestion.