Skip to content

support Parse Relation #169

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
WahdanZ opened this issue May 2, 2019 · 15 comments
Closed

support Parse Relation #169

WahdanZ opened this issue May 2, 2019 · 15 comments

Comments

@WahdanZ
Copy link
Contributor

WahdanZ commented May 2, 2019

support relation object one to many and many to many
https://docs.parseplatform.org/rest/guide/#relations
http://docs.parseplatform.org/android/guide/#relational-data

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented May 2, 2019

@WahdanZ
queries and create with one to many (Pointer): yes.
See section Relational queries or ** Objects** in README.MD

queries and create with Many to many: No
I started to implement, but as I have never used I did not understand the concept

@WahdanZ
Copy link
Contributor Author

WahdanZ commented May 2, 2019

not queries but I'm talking about creating a relation between object

// let’s say we have a few objects representing Author objects
ParseObject authorOne =
ParseObject authorTwo =
ParseObject authorThree =

// now we create a book object
ParseObject book = new ParseObject("Book");

// now let’s associate the authors with the book
// remember, we created a "authors" relation on Book
ParseRelation<ParseObject> relation = book.getRelation("authors");
relation.add(authorOne);
relation.add(authorTwo);
relation.add(authorThree);

// now save the book object
book.saveInBackground();

thre is a ParseRelation object.

ParseUser user = ParseUser.getCurrentUser();
ParseRelation<ParseObject> relation = user.getRelation("likes");
relation.add(post);
user.saveInBackground();

http://docs.parseplatform.org/android/guide/#using-parse-relations

@WahdanZ
Copy link
Contributor Author

WahdanZ commented May 2, 2019

three is different between pointer and relation
A Relation is for when you want a long list of related classes, where an array doesn't work, or when you want to query the related objects as needed and not have the list included every time you load the containing object.

Basically you have 4 options with Parse:

Pointer - single reference to another class (1 to 0..1)
Array - collection of pointers, loaded with the object every time (1 to 0..n, small lists)
Relation - collection of pointers, like a join table in SQL (handled under the covers for you), you must run a query against it to load values (1 to 0..n)
Custom join class - really just another object (like many-to-many join in SQL) with a Pointer to each side plus any related information (1..n to 1..n)

@WahdanZ
Copy link
Contributor Author

WahdanZ commented May 2, 2019

like facebook post the author will be a pointer for the post owner, but likes will be a relation object of the users who like this post

@RodrigoSMarques
Copy link
Contributor

RodrigoSMarques commented May 2, 2019

See example below:
The user field that is a relationship with ParseUser (Pointer)
The users field is a list of ParseUsers. (List of Pointers).

Was this?

  final ParseUser user = await ParseUser.currentUser() as ParseUser;
  var parseObject = ParseObject("TestAPI");
  parseObject.set<ParseUser>("user", user);
  parseObject.set<List<ParseUser>>("users", [user, user]);
 ParseResponse apiResponse = await parseObject.save();

Captura de Tela 2019-05-02 às 15 57 27

Users field content:

[
  {
    "__type": "Pointer",
    "className": "_User",
    "objectId": "0C6ptX39c8"
  },
  {
    "__type": "Pointer",
    "className": "_User",
    "objectId": "0C6ptX39c8"
  }
]

@WahdanZ
Copy link
Contributor Author

WahdanZ commented May 2, 2019

it's different between pointer and relation, If the array of pointer likely to be more than 100 (recommended limit by Parse), it is better you go with relations. Because arrays don't scale to large relationships.

https://www.youtube.com/watch?v=x70G_LPlW60

see the implementation of ParseRelation

@RodrigoSMarques
Copy link
Contributor

I understood. Today lib does not support this.
I started to query, but I did not go any further.

@zenz
Copy link
Contributor

zenz commented May 6, 2019

I also encountered the same problem when trying this plugin. I have to modify parse class structure currently.
Hope the related function can be available soon.

@yulingtianxia
Copy link
Contributor

@WahdanZ I had add ParseRelation on branch release/1.0.22

@zenz
Copy link
Contributor

zenz commented Jun 6, 2019

@yulingtianxia it's reversed back to 1.0.21. there's no 1.0.22 release yet.
And, could you please provide some samples how to use the relation API?

@yulingtianxia
Copy link
Contributor

@zenz
Copy link
Contributor

zenz commented Jun 6, 2019

I gave it a try. and it seems broken something.
My test app can run with 1.0.21 without error. but after switch to 1.0.22, it will bring me this error:
E/flutter (12539): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null.

Since 1.0.22 was not released yet, so I use git url to fetch it:

dev_dependencies:
  parse_server_sdk:
    git:
      url: [email protected]:phillwiggins/flutter_parse_sdk.git
      ref: 7b24830d4dda74ed7f3cc9d077d4b305d0a69c59

Here's my sample:
https://github.com/zenz/flutter_parse_sample

@yulingtianxia
Copy link
Contributor

I gave it a try. and it seems broken something.
My test app can run with 1.0.21 without error. but after switch to 1.0.22, it will bring me this error:
E/flutter (12539): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null.

Since 1.0.22 was not released yet, so I use git url to fetch it:

dev_dependencies:
  parse_server_sdk:
    git:
      url: [email protected]:phillwiggins/flutter_parse_sdk.git
      ref: 7b24830d4dda74ed7f3cc9d077d4b305d0a69c59

Here's my sample:
https://github.com/zenz/flutter_parse_sample

@phillwiggins Hi, this issue(#190 (comment)) can also reappear in his sample.

@zenz
Copy link
Contributor

zenz commented Jun 18, 2019

I had figure out why this issue #190 happened.
verison 1.0.22 need masterKey while do Parse().initialize().
When those functions don't need masterKey permission, please don't ask for it.

@phillwiggins
Copy link
Member

There's not been much movement on this recently. Are we safe to close?

@WahdanZ WahdanZ closed this as completed Oct 14, 2019
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

5 participants