Skip to content

How can I write this kind of query? #176

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

Closed
alparslantopbas opened this issue May 27, 2019 · 4 comments
Closed

How can I write this kind of query? #176

alparslantopbas opened this issue May 27, 2019 · 4 comments

Comments

@alparslantopbas
Copy link

alparslantopbas commented May 27, 2019

Hi,
How can I write this kind of query? I think named is "relational query".
For example, there are two tables: tblOrders and tblProducts

Like these:
tblOrders
objectId
productId (Pointer)
Date
Quantity

tblProducts
objectId
ProductName

I want to this kind of result:
tblOrders.objectId tblOrders.productId tblProducts.ProductName tblOrders.Date tblOrders.Quantity

So,
var apiResponse = await ParseObject('tblOrders').getAll();

but, how can I add "ProductName" into query?
Like T-SQL View structure?

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented May 28, 2019

Hi @alparslantopbas
See this example.
Maybe I made a mistake, because I typed without testing, based on a code I have.

QueryBuilder queryBuilder = QueryBuilder<ParseObject>(ParseObject('tblOrders'));
queryBuilder.includeObject(['productId']);
ParseResponse parseResponse = await queryBuilder.query();

if (parseResponse.success && parseResponse.results != null) {
  final ParseObject tblOrders = parseResponse.results[0] as ParseObject;
  final ParseObject tblProducts = tblOrders.get<ParseObject>('productId');
  print(tblOrders.get<String>('objectId'));
  print(tblOrders.get<String>('Quantity'));
  print(tblProducts.get<String>('objectId'));
  print(tblProducts.get<String>('ProductName'));
}

@alparslantopbas
Copy link
Author

alparslantopbas commented May 28, 2019

Hi @rodrigosmarques,
Thank you very much, yes it works.
But it works only for one record (one row) (parseResponse.results[0]).
How can I all of the records?

This doesn't work:

final List<ParseObject> tblOrders = parseResponse.results as List<ParseObject>;
final List<ParseObject> tblProducts = tblOrders.get<ParseObject>('productId') as List<ParseObject>;

@RodrigoSMarques
Copy link
Contributor

Hi @alparslantopbas
Hello, I did with the first just as an example.
Make a loop in the parseResponse.results items.
For each list item retrieve tblProducts

@alparslantopbas
Copy link
Author

Hi @RodrigoSMarques,
Yes, it is possible to do that way. I did.
Thank you very much for your help.

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