• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

CouchDB accessing composed column

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't MAKE me come back there with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic