Odata - nested $select and $expand [duplicate] - select

This question already has answers here:
odata - combining $expand and $select
(2 answers)
Closed 7 years ago.
http://services.odata.org/V4/Northwind/Northwind.svc/
I'm trying to get all Customers, their Orders and corresponding Order_Details at once and using nested $expand for that. To query the data I'm using following link: http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$expand=Orders($expand=Order_Details)
Now I'm trying to limit the data using $select. The problem is that I can not find the proper syntax to use $select for the middle table - Orders. I can apply it just to the top table - Customers and to the bottom one - Order_Details like this:
http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$select=CustomerID&$expand=Orders($expand=Order_Details($select=UnitPrice))
Is it possible to use $select also for tables in between, in my case for Orders?

Thanks #nlips for his comment.
It is possible to use $select for the middle table by just separating select and expand with semicolon:
http://services.odata.org/V4/Northwind/Northwind.svc/Customers?$select=CustomerID&$expand=Orders($select=OrderID;$expand=Order_Details($select=UnitPrice))

Related

Delete multiple rows from a table with a single query when the row ids are not consecutive [duplicate]

This question already has answers here:
How to delete from a table where ID is in a list of IDs?
(3 answers)
Closed 2 years ago.
I've created a mass delete feature on my website where the user gets to select which rows they want to delete before pressing a delete button. It currently works by creating an array containing each selected row's id, before looping through that array and calling a delete query for each one. I was wondering if there is a way to do with with a single query, while keeping in mind that the user may want to keep a row that in between the rows they would like to delete.
You can use IN clause for this.
Sample query may look like below
DELETE FROM table WHERE id IN (1, 4, 6, 7)

How to access unmapped data in embedded forms? [duplicate]

This question already has answers here:
Symfony - retreive unmapped fields in nested forms
(2 answers)
Closed 2 years ago.
I've embedded a collection of forms like here: Embedding a collection of forms. Empty results
In my controller, I would like to access (get and set) unmapped fields, like view, new, edit, delete.
How do I do that?
I've tried dumping the form, but I couldn't find the submitted data anywhere.
You can just use
$request = Request::createFromGlobals();
$request->get('formname')['formfield']
to get your form values.

Sails 1.0 Group By

Now that groupBy is deprecated, how can I mimic a SQL command like SELECT COUNT(*) FROM table GROUP BY xxx using the Waterline ORM ?
This page recommends using .sum() and .avg() but these methods are for number-type columns. Here I want to be able to count the rows of grouped columns, whatever type it is.
I think for specific groupBy query, you've got two choices.
The first one is a 2 step action.
1) Select all the unique element "group by field" you've got in the database.
2) Then count the record for each unique group by field element.
The second one is to use .sendNativeQuery() wich allow you to send a native SQL query to the datastore (you can use this only if you use a real SQL server and not the embedded Sails.JS database)
sendNativeQuery() Documentation

odata query $filter on nested navigation property

I have a Entity Customer containing Orders Navigation Property and Order containing Products Navigation Property(One-Many).
Now how i can filter all customers have ordered a Specific Product. I have tried every permutation as mentioned below but it is throwing odata exceptions:
trial 1) Customers?$filter=Orders/Products/any(d:d/ProductCode eq 'code1')
trial 2) Customers?$expand=Orders($expand=Products))&$filter=Orders/Products/any(d:d/ProductCode eq 'code1')
trial 3) Customers?$expand=Orders($expand=Products))&$filter=Orders/any(d:d/Products/ProductCode eq 'code1')
Please suggest correct format for odata query.
I think that you need two different any clauses here as I think that you are asking for "customers with any order that in turn has any product that has the product code 'code1'"
So I think that it should look like this:
Customers?$filter= Orders/any(o: o/Products/any(p: p/ProductCode eq 'code1'))
Here is an example using the example TripPin OData service: http://services.odata.org/V4/TripPinServiceRW/People?$filter=Friends/any(f:%20f/Trips/any(t:%20t/Name%20eq%20'Trip%20in%20US'))&$expand=Friends($expand=Trips)

Separate search in different tables with sphinx [duplicate]

This question already has answers here:
Searching a particular index using Sphinx, from multiple indexes, through PHP script
(2 answers)
Closed 8 years ago.
In my case content are saving in table
content_en
Search with sphinx works good.
I would to add another table content_es and make search in this table.
And if user will be search on en version site - i would use content_en table, if on spain version - content_es table.
I can search in 2 tables and on PHP side make filter, but I think it's not correct.
How it's make correct ? (like $sphinx->SetOption() or $sphinx->SetIndex()) ?
$res = $cl->Query($query,"content_es");