Skip to content
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

Having multiple object types in RLMResults #3112

Closed
koenpunt opened this issue Jan 16, 2016 · 3 comments
Closed

Having multiple object types in RLMResults #3112

koenpunt opened this issue Jan 16, 2016 · 3 comments
Assignees
Labels

Comments

@koenpunt
Copy link

Is it possible to have objects of multiple types in a single RLMResults?

I'm using RLMResults as datasource for my UITableView, and it would be nice if the different datatypes the tableview represents, are all in a single RLMResults

@mishagray
Copy link

would your objects logically have a common base class? How would you even do a query?

In Core Data you could have a common 'parent' object and do a single query that might return different objects. But in general it can be a bit confusing.

I've done two things in the past to to your solution...
if I am sectioning the table by "Type" - just use a different Results object for each "section". You could have a data model like var resultBySection : [RLMResults]

But if you want a "mix" model (like say... a Facebook feed?)... then you may want to consider a action or proxy object that has a relationship to the "real" object.

class FeedItem : Object {

      dynamic var date : NSDate()
      dynamic var itemObject: Object?
}

And you could just add properties to the "FeedItem" that will let you sort it the way you want (in my example, I assume by date), but have all the "real" data using the "itemObject" relationship. I've never tried using an 'Object' pointer for a relationship... but it could work? Would that work?

@jpsim jpsim added the T-Help label Jan 17, 2016
@jpsim
Copy link
Contributor

jpsim commented Jan 17, 2016

Have you read the Model Inheritance section of our docs along with the in-depth code samples it links to?

That should explain everything you need to know about why a single RLMResults can't contain multiple types, along with work-arounds for many scenarios.

If anything isn't clear in that documentation, please let us know and we'll be sure to review it.

@jpsim jpsim self-assigned this Jan 17, 2016
@jpsim jpsim added the pending label Jan 17, 2016
@koenpunt
Copy link
Author

@mishagray @jpsim thanks for your responses. I went with the proxy model (FeedItem), which fits my case fairly well.

@realm-ci realm-ci removed the pending label Jan 18, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants