Hi, I''m trying to retrieve ALL fields from an Oracle database table, as well as a subset of them, under a different name. The equivalent select statement would be: SELECT *, NAME_EN AS NAME, DESC_EN AS DESCRIPTION FROM MYTABLE; The problem is that this isn''t allowed (Oracle-specific?). Is there a way I can do this using Rails'' find method? Thanks, Chris. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
cn u show m d bit code of fields subset On Fri, Feb 22, 2008 at 3:20 PM, gers32 <cbu.kitry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I''m trying to retrieve ALL fields from an Oracle database table, as > well as a subset of them, under a different name. > > The equivalent select statement would be: > > SELECT *, NAME_EN AS NAME, DESC_EN AS DESCRIPTION FROM MYTABLE; > > The problem is that this isn''t allowed (Oracle-specific?). Is there a > way I can do this using Rails'' find method? > > Thanks, > > Chris. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I don''t quite understand your question... sorry. But someone suggested a solution that I like; assuming I could get it to work: I created the following method in the Model: def description self[:desc_en] end and in the Controller, I have: def by_id_xml @my_model = MyModel.find( params[:id] ) render :xml => @my_model.to_xml end Unfortunately, by_id_xml still returns the same XML structure, with all of the table''s fields, but without the new field "description"... Is this due to the fact that description is a method and not a class variable? In which case, is there a way I can tell ActiveRecord to add the "description" field to the model? Thanks, Chris. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 25 Feb 2008, at 09:25, gers32 wrote:> > I don''t quite understand your question... sorry. But someone suggested > a solution that I like; assuming I could get it to work: > > I created the following method in the Model: > > def description > self[:desc_en] > end > > and in the Controller, I have: > > def by_id_xml > @my_model = MyModel.find( params[:id] ) > render :xml => @my_model.to_xml > end > > Unfortunately, by_id_xml still returns the same XML structure, with > all of the table''s fields, but without the new field "description"... > Is this due to the fact that description is a method and not a class > variable? In which case, is there a way I can tell ActiveRecord to add > the "description" field to the model?to_xml takes a bunch of options for that kind of thing. In particular, the :methods key is an array of methods to call and include in the xml, so in your case @my_model.to_xml :methods => [:description] ought to do the job. Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Fred, that worked. Chris. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Now I have a new problem, derived from the one above... My Rails code looks like this: ########################## @my_data = MyTable.find( :all, :select => "ID, CODE, DESC_FR AS DESCRIPTION_I18N", :conditions => conditions_list) @my_data_i18n = @my_data.to_xml :methods => [:description_i18n] render :xml => @my_data_i18n ########################## The resulting XML structure lacks a value for the DESCRIPTION_I18N field, unless I comment out the :select option in the find method... Unfortunately, I need to restrict the number of fields in my SELECT statement, because the table has a large number of them. Is this caused by an incorrect usage of :select (specifically using AS)? Thanks, Chris. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
My problem is solved: I removed "AS DESCRIPTION_I18N" from the SQL query, because the variable is created in to_xml(), which expects to see DESC_FR. Thanks to Fred, Chris. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---