File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ruby and the fly likes CouchDB accessing composed column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Languages » Ruby
Bookmark "CouchDB accessing composed column" Watch "CouchDB accessing composed column" New topic

CouchDB accessing composed column

Paulo Carvalho
Ranch Hand

Joined: Nov 12, 2008
Posts: 57

In my RoR application, I am using Couchrest_model to access a CouchDB database.

I have a model which represents an scientific Article.
I am going to simplify my model to explain it better. An article can have a title, a year and one or more authors.

In the couchDB database, an article can be represented like this:

(In the case the article only have an author)


In the case my article have only one author, I can access author's information (name and age) like this:

But, how can I access the information of authors if the article have more than 1 author?
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

I'm not terribly familiar with CouchRest but here's my guess from a quick glance.

I think you need to define your author as another type and reference it accordingly:

This might mean that you have to always make your Couch records get saved in the more complicated array format that you used, even when there's only one author. I suppose you could try it both ways and see if it works.

A good workman is known by his tools.
Paulo Carvalho
Ranch Hand

Joined: Nov 12, 2008
Posts: 57

Thanks for your answer. After trying and trying, I figure that the object returned was an array of objects.
So depending on the scenario, I test if the returned object is an instance of array or something else and then I execute the proper action.

Best regards.
I agree. Here's the link:
subject: CouchDB accessing composed column
It's not a secret anymore!