saintsystems / odata-client-php

OData Client Library for PHP
MIT License
141 stars 103 forks source link

query for enum values #133

Closed ebrahimradi closed 1 year ago

ebrahimradi commented 1 year ago

I want to make a query to call "data/DCTCustTrans?$filter=TransType eq Microsoft.Dynamics.DataEntities.LedgerTransType'GeneralJournal'"

but with normal query builder and having something like:

$builder->where("TransType", "Microsoft.Dynamics.DataEntities.LedgerTransType'GeneralJournal'")->get()

it doesn't work!

any idea how I can have this query?

anderly commented 1 year ago

See the enum test case here which shows the correct syntax.

ebrahimradi commented 1 year ago

Thank you @anderly , it is really interesting that it is working! because single quote should be double! from here:

Single quote in OData Query need to present in pairs. Which means if your string contains one single quote, we need to "double" it. For example, the string we would like to use under Filter Query with the field Department is: Men's Guest Services Then the formula should be: Department eq 'Men''s Guest Services'

and I tried with double and it didn't work also. so the trick is having backslash!

anderly commented 1 year ago

@ebrahimradi,

I think what that link you sent is saying is that if your enum value has a single quote within it, then you need to double it because the single quote on either end of the enum value is denoting the start and end of the value. So, you have to double any single quotes inside of the enum value to escape it. And, yes, the backslash escapes the single quote.

anderly commented 1 year ago

Marking as closed.