Hello, I am writing a RoR application that connects to a couchDB database using couchrest_model. The definition of my model is the following one: class BdsDataAuthor < CouchRest::Model::Base property :id, Integer property :first_name, String property :last_name, String end I would like to be able to get the list of the model columns, e.g., the result of BdsDataAuthor.columns would be [id, first_name, last_name] Is it possible? I saw that active_record provides this kind of method (column_names), but since I am not using active_record... A solution that I tried is to create a method in the model class (it works but its not the "best" solution...): def getColumns columns = Array.new columns << "id" columns << "first_name" columns << "last_name" end Any idea/suggestion to solve this problem? Thank you -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
*columns*(table_name, name = nil) *public* Returns an array of Column<http://apidock.com/rails/ActiveRecord/ConnectionAdapters/Column> objects for the table specified by table_name. See the concrete implementation for details on the expected parameter values. Try this. On Mon, May 21, 2012 at 3:02 AM, Paulo Carvalho <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Hello, > > I am writing a RoR application that connects to a couchDB database using > couchrest_model. > > The definition of my model is the following one: > > class BdsDataAuthor < CouchRest::Model::Base > property :id, Integer > property :first_name, String > property :last_name, String > end > > > I would like to be able to get the list of the model columns, e.g., the > result of > BdsDataAuthor.columns would be [id, first_name, last_name] > > Is it possible? I saw that active_record provides this kind of method > (column_names), but since I am not using active_record... > > A solution that I tried is to create a method in the model class (it > works but its not the "best" solution...): > > def getColumns > columns = Array.new > columns << "id" > columns << "first_name" > columns << "last_name" > end > > Any idea/suggestion to solve this problem? > > Thank you > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Atenciosamente, Guilherme Pereira Dutra, Fone: (34) 8407-0109 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ah sorry, I didn''t see that you aren''t using Active Record... On Mon, May 21, 2012 at 8:59 AM, Guilherme Dutra <guipereira07-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> *columns*(table_name, name = nil) *public* > > Returns an array of Column<http://apidock.com/rails/ActiveRecord/ConnectionAdapters/Column> objects > for the table specified by table_name. See the concrete implementation > for details on the expected parameter values. > > > Try this. > > On Mon, May 21, 2012 at 3:02 AM, Paulo Carvalho <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > >> Hello, >> >> I am writing a RoR application that connects to a couchDB database using >> couchrest_model. >> >> The definition of my model is the following one: >> >> class BdsDataAuthor < CouchRest::Model::Base >> property :id, Integer >> property :first_name, String >> property :last_name, String >> end >> >> >> I would like to be able to get the list of the model columns, e.g., the >> result of >> BdsDataAuthor.columns would be [id, first_name, last_name] >> >> Is it possible? I saw that active_record provides this kind of method >> (column_names), but since I am not using active_record... >> >> A solution that I tried is to create a method in the model class (it >> works but its not the "best" solution...): >> >> def getColumns >> columns = Array.new >> columns << "id" >> columns << "first_name" >> columns << "last_name" >> end >> >> Any idea/suggestion to solve this problem? >> >> Thank you >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > Atenciosamente, > Guilherme Pereira Dutra, > Fone: (34) 8407-0109 >-- Atenciosamente, Guilherme Pereira Dutra, Fone: (34) 8407-0109 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Monday, 21 May 2012 01:02:43 UTC-5, Ruby-Forum.com User wrote:> > Hello, > > I am writing a RoR application that connects to a couchDB database using > couchrest_model. > > The definition of my model is the following one: > > class BdsDataAuthor < CouchRest::Model::Base > property :id, Integer > property :first_name, String > property :last_name, String > end > > > I would like to be able to get the list of the model columns, e.g., the > result of > BdsDataAuthor.columns would be [id, first_name, last_name] > > Is it possible? I saw that active_record provides this kind of method > (column_names), but since I am not using active_record... > > A solution that I tried is to create a method in the model class (it > works but its not the "best" solution...): > > def getColumns > columns = Array.new > columns << "id" > columns << "first_name" > columns << "last_name" > end > > Any idea/suggestion to solve this problem? > >I haven''t used CouchRest, but a quick skim of this: https://github.com/couchrest/couchrest_model/blob/master/lib/couchrest/model/properties.rb seems to indicate that what you''re looking for could be accomplished with: BdsDataAuthor.properties_by_name.keys --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/J1WRdba-sY8J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for your answer. I will try the properties_with_values method to see if it returns what I want. Best regards Matt Jones wrote in post #1061503:> On Monday, 21 May 2012 01:02:43 UTC-5, Ruby-Forum.com User wrote: >> property :first_name, String >> >> Any idea/suggestion to solve this problem? >> >> > I haven''t used CouchRest, but a quick skim of this: > >https://github.com/couchrest/couchrest_model/blob/master/lib/couchrest/model/properties.rb> > seems to indicate that what you''re looking for could be accomplished > with: > > BdsDataAuthor.properties_by_name.keys > > --Matt Jones-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.