Comments (8)
I fix the problem by creating my own type by creating JsonB type which extends type and doesn't use json_encode when inserting data.
from jsonbbundle.
In fact, i think this was the JSON i tried to insert in my DB.
In the Postgre request, i tried to insert a JSON and not an object to encode in JSON so it was encoded twice and decoded once...
I have overloaded the JsonArrayType to handle all the case :
- Insert a JSON directly
- Insert an object
Thanks for your help it helped me :)
from jsonbbundle.
And the stored data is a JSON string, not an array, so i can't search on it.
Some help please ?
from jsonbbundle.
@QuentinCurtet Have you set up the Bundle as described in the documentation and defined it as jsonb. So this should make the column JSONB. Have a look in the tests for a sample setup. Debug the query from Doctrine to see the raw sql and check if that is correct or not. Basically everything should work as described in the docs.
from jsonbbundle.
Hello,
Thanks for your answer.
I set up the bundle as described in the documentation, and in fact it is defined as jsonb in my Postgre DB.
The problem is that the JSON is not stored as an array but as a string so i can't use the Postgre functions...
I'll look in the tests the setup, and if i don't find anything, i'll be back ^^
from jsonbbundle.
My code seems OK :
`class ProductController extends Controller
{
/**
* @return Response
*/
public function insertAction()
{
$em = $this->getDoctrine()->getManager();
$pen = new Product();
$pen->setAttributes('{"id":"1","name":"Stylo","price":"9.99","color":"red"}');
$bag = new Product();
$bag->setAttributes('{"id":"2","name":"Sac","price":"29.99"}');
$em->persist($pen);
$em->persist($bag);
$em->flush();
return new Response($pen->getAttributes().' and '.$bag->getAttributes());
}
/**
* @return Response
*/
public function selectAction()
{
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository('AppBundle:Product');
$results = $repository->selectDB();
return $this->render('AppBundle:Product:index.html.twig', ['results' => $results]);
}
}`
And in my repository :
`class ProductRepository extends \Doctrine\ORM\EntityRepository
{
/**
* @return array
*/
public function selectDB()
{
$rsm = new ResultSetMapping();
$rsm->addEntityResult('AppBundle\Entity\Product', 'p');
$rsm->addFieldResult('p', 'id', 'id');
$rsm->addFieldResult('p', 'attributes', 'attributes');
$query = $this->_em->createNativeQuery("SELECT p.id, p.attributes FROM Product p WHERE (p.attributes->>'price')::float > 9", $rsm);
return $query->getResult();
}
}`
But the result is empty.
Some help ?
from jsonbbundle.
The problem is caused by the json_encode of the json_array type that add some double quotes and backslashes and when the json is decoded, it's not an array...
from jsonbbundle.
Perfect, not sure why you were the first to report this problem, it seems it works for most people :/. Anyway, nice fix.
from jsonbbundle.
Related Issues (6)
- can't implement JSONB "key exist" functions HOT 11
- Error when excuting doctrine:schema:update HOT 2
- Doctrine\DBAL\Types\JsonArrayType is deprecated use JsonType instead HOT 1
- Missing LICENSE file HOT 1
- Doctrine doesn't fill jsonb attributes of 2 or more classes who have fields with equal names HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonbbundle.