Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

CouchDB accessing composed column

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

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?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paulo Carvalho
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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.
 
He does not suffer fools gladly. But this tiny ad does:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic