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)
OR
In the case my article have only one author, I can access author's information (name and age) like this:
Article.author.name
Article.author.age
But, how can I access the information of authors if the article have more than 1 author?
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.
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.
Don't MAKE me come back there with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss