Two different properties from the same property

5 views
Skip to first unread message

Filipe Rocha

unread,
Jan 17, 2014, 1:16:58 PM1/17/14
to couc...@googlegroups.com
Hi,
I have a property :clinical_sign which represents the main clinical sign. But I'd also would like to include a collection of clinical signs for more details. I have two models Patient and ClinicalSign.
Basically all I want is a belongs_to and a collection_of clinical signs on different fields. Can you help me?

Thanks,
Filipe

Samuel Lown

unread,
Jan 17, 2014, 2:57:38 PM1/17/14
to couc...@googlegroups.com
Hi Filipe,

There should not be a problem with including both:

class Patient < CouchRest::Model::Base
  belongs_to :clinical_sign
  collection_of :clinical_signs
end

If you wanted to use shorter helper method names, you could also do:

class Patient < CouchRest::Model::Base
  belongs_to :sign, class_name: 'ClinicalSign'
  collection_of :signs, class_name: 'ClinicalSign'
end

These will of course store the ids of the associated ClinicalSign documents inside the Patient. If you wanted to embed a ClinicalSign object, you'd use the property field:

class Patient < CouchRest::Model::Base
  property :clinical_sign, ClinicalSign
  property :clinical_signs, [ClinicalSign]
end

Hope that helps.

sam



--
You received this message because you are subscribed to the Google Groups "CouchRest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to couchrest+...@googlegroups.com.
To post to this group, send email to couc...@googlegroups.com.
Visit this group at http://groups.google.com/group/couchrest.
For more options, visit https://groups.google.com/groups/opt_out.



--

Filipe Rocha

unread,
Jan 21, 2014, 12:16:08 PM1/21/14
to couc...@googlegroups.com, Samuel Lown
Hi Sam,
thanks. You've helped a lot! :)

Since I’m asking for help how would you create a view that instead of showing the ids it would show the sign_name property of ClinicalSign?

Thanks,
Filipe

De: Samuel Lown sam....@gmail.com
Responder: couc...@googlegroups.com couc...@googlegroups.com
Data: 17 Jan 2014 at 19:57:59
Para: couc...@googlegroups.com couc...@googlegroups.com
Assunto:  Re: [couchrest] Two different properties from the same property
Reply all
Reply to author
Forward
0 new messages