On Jul 12, 2014, at 10:42 AM, Mark <[email protected]> wrote:

> Sure. I'm using the array of keys for a table view. (In the actual app, there 
> are a few more fields I export). I use a related CQLLiveQuery in a 
> nstableviewdatasource. I just pull in the keys for the items in the 
> tableviewcell instead of having to load the model for every row.

It sounds like you want to display a list of the comments on a post, then? In 
that case you don't want the text of the post to be the key, since the key is 
what the view is sorted by. It doesn't sound useful to get a list of all the 
comments in the entire database in alphabetical order :) Instead you probably 
want the view to have a primary sort by post ID (so you can use a range to get 
the comments on a single post) and a secondary sort by date (so you can show 
them in chronological order).

This section from JChris's old CouchDB book talks about how to do pretty much 
exactly that.

As for getting the user name -- there are two choices:
Put the user name (along with the ID) in the comment document. Then it can be 
emitted into the view. The downside is that if users can change their names, 
you have to go through every comment and update the name.
Emit only the user ID in the view value, then look up the user name while 
displaying, i.e. get the document with that ID and get its "name" property. 
This shouldn't cause much DB activity, if there aren't a huge number of users, 
because CBL caches recently-accessed documents in memory. (Really, it's exactly 
what a relational database would be doing when you use a JOIN in the query.) If 
it does turn out to be an issue, you can construct a view that maps user ID to 
user name, and keep a live query of it; that will end up caching the mapping 
and keeping it up to date.

--Jens

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/399AA96C-3DDE-4445-9844-1707A0A3A9F0%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to