Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Stone Preston
42,016 PointsParse Data Modeling help
Im designing an iOS app and was having some trouble deciding on the best data model for an aspect of it.
Basically I want to display content relative to a users City using parse. And people could add their own content to that city.
What would be the best way to model this in parse? I was thinking I could create a City class and store cities in that table, and add a relation for the content to that cities table. So have a Cities class and that class would have the relation hasContent or whatever. But some of you might have some better ideas. Maybe Amit Bijlani and Ben Jakuben could provide some insight.
2 Answers
John W
21,558 PointsFrom a relational standpoint, your approach is completely valid and adhere nicely to the normalization principle. Having 3 tables (City, Content, User) allows maximal modularization of your model. Two thumbs up!
Here is an alternative for you to think about:
Depending on the scale of your project and the expected size of content, an alternative (non-relational) solution is to include Content into your City class as an array (also an acceptable column type in Parse). Of course, each entry of the content might require additional information such as user, timestamp, etc. Which you can opt to use a dictionary (now you have an array of dicts), which can easily be serialized as JSON if so desired.
There's a drawback for a non-relational solution, of course. In this design, querying content by user would be difficult. You would have to scan through all cities' contents to find what you need. Hence, the "ideal" solution, if such thing exists, depends entirely on the expected access pattern of your app. Are users expected to look up contents by user? Or should you prioritize access to a City's content (single query instead of 2)? Or, is performance even an issue.
Stone Preston
42,016 PointsAlright looks like I'll go for the first option then. Thanks for the help!
Stone Preston
42,016 PointsStone Preston
42,016 Pointsperformance would be an issue. The content would contains images/descriptions/comments etc which could be fairly spacious. At the moment, the user class would be solely for login purposes. I have plans on implementing more social features in the future though but for nothing to serious. I would want the queries to be as quick as possible
As far as querying content goes, I would get the users current location (current city) and then query the cities table for that city, and then query the content of the city itself.
I havent actually made anything yet, so the way I think it should work isnt totally defined as of yet.
John W
21,558 PointsJohn W
21,558 PointsIf your content contains substantial data (especially images), then you have no choice but to normalize. Some databases such as mongoDB supports large "columns," but it is not the case for Parse, which limits the size of each object to 128 kb as discussed in (this post)[https://parse.com/questions/an-array-field-has-a-size-limit].