+ Start a Discussion
juhanajuhana 

SmartStore joined/nested queries ?

Hi,

 

I'm using SmartStore in hybrid offline development. In online mode, I can do queries like:

Select Id,(select Id from Events),(select Id from Contacts) from Account

 But how to do this with SmartStore using smart queries ?

 

 

 

bhariharanbhariharan
Please take a look at the smart SQL queries used in the NativeSqlAggregator
sample app. This demonstrates the syntax of smart SQL and how to perform
complex aggregate queries similar to the query you mentioned.

--
Sent from my iPhone
juhanajuhana
select {accounts:_soup},{events:_soup} from {accounts},{events}

 Does not work, even SmartSql is formed and queried, SmartSync.js crashes. Is this query right or not ?

Also tried query only the Id fields but still the same error.

bhariharanbhariharan

I'm assuming "accounts" and "events" are your table names? Is "_soup" your field name? Assuming you're querying the "Id" field from both these tables, where the "Id" value matches, the query would look like:

 

SELECT {Accounts:Id}, {Events:Id} FROM {Accounts}, {Events} WHERE {Accounts:Id} = {Events:Id}

 

mobile1.390759152613193E12mobile1.390759152613193E12
Hi Bhariharan, I have a similar problem with SmartQuery using Smartstore Offline. 
I am using mobile SDK 2.1 and I am extending the AccountEditor application. 
I am trying to run a smartQuery to get from Offline Smartstore all the contacts of that partirocal Account. I arrive to run the following smartQuery:
smartSql = "SELECT {contacts:_soup} FROM {contacts} WHERE {contacts:Account.Id} IN ( '001E000000Hl5XEIAZ') ORDER BY LOWER({contacts:Id})";

Here is the fieldlist of my contact Collection Model: fieldlist: ["Id","Account.Id","FirstName","LastName", "Phone", "Email","Birthdate","Owner.Name", "LastModifiedBy.Name", "LastModifiedDate"],

Only thing I get on the console is: ------> Calling errorCB for smartstoreClient:runSmartQuery.

If I change the contacts:Account.Id with other contact fields like contacts:FirstName, I don't get the error any more, but Of course I don't obtain the result I want. 
Start to think that I can't use the Parent Id field (Account.Id in this case) in the Model Object.

Please help

Thanks 

Maurizio.