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

JSONB_CONTAINS and ::jsonb #77

Open
jraller opened this issue Nov 12, 2021 · 3 comments
Open

JSONB_CONTAINS and ::jsonb #77

jraller opened this issue Nov 12, 2021 · 3 comments

Comments

@jraller
Copy link

jraller commented Nov 12, 2021

JSONB_CONTAINS is included in the codebase under the Postgres section, but isn't mentioned in the documentation. It appears to generate the correct SQL with the exception of not casting either parameter with ::jsonb.

Is there a way to use JSONB_CONTAINS with ->setParameter() that will result in the field reference and the parameter value being followed by ::jsonb?

I was able to use createNativeQuery and ResultSetMappingBuilder and get the expected result, and I've been able to write an OrX condition using JSON_GET_PATH_TEXT to or together several paths, but I'd prefer to use querybuilder and JSONB_CONTAINS if possible.

@jraller
Copy link
Author

jraller commented Nov 13, 2021

While this package doesn't include a DBAL jsonb type using another package that had that improved things. Setting both the ORM\Column type on the entity and setting the type in setParameter to 'jsonb' combined with a database migration to pick up the entity change improved things.

@jraller
Copy link
Author

jraller commented Nov 13, 2021

Further investigation shows that the parameter doesn't need to be typed with jsonb, just the entity column. Likely a documentation improvement would clear this up where the column can be set to jsonb instead of the built in DBAL JSON type.

@quentint
Copy link

quentint commented Mar 1, 2023

I know this is an old issue, but I faced the same questions and I'm sure my experience could help someone 😉

I could not get this bundle to work (Symfony 6, PostgreSQL 14) so I ended up using opsway/doctrine-dbal-postgresql. After thinking more about this, I think my PR here helps when dealing with existing fields: opsway/doctrine-dbal-postgresql#39

Maybe this bundle could also benefit from it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants