Hi people I need to write a raw sql query in rails 3. But I don''t know where should I do this, in the model or in the controller? Thanks -- 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 9 August 2011 18:34, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi people > > I need to write a raw sql query in rails 3. But I don''t know where > should I do this, in the model or in the controller?If you are not sure where it should be then firstly I would ask whether you are sure you need to write a raw sql query. If you do need to do that then almost always it should be in a model. However without knowing more details of what it does and why, it is impossible to give an absolute answer. Colin -- 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.
Well I have two non related models, but I need to update an attribute value of one model using a value from the other one. I''ve tried using callbacks(after_create update_attribute), but it didn''t work because they are not related and because I need "extra" conditions. So I think I could solve this using a raw sql query On Aug 9, 3:43 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 9 August 2011 18:34, Angelo Cordova <acord...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi people > > > I need to write a raw sql query in rails 3. But I don''t know where > > should I do this, in the model or in the controller? > > If you are not sure where it should be then firstly I would ask > whether you are sure you need to write a raw sql query. If you do > need to do that then almost always it should be in a model. However > without knowing more details of what it does and why, it is impossible > to give an absolute answer. > > Colin-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 August 2011 21:47, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: Please don''t top post, it makes it difficult to follow the thread. Insert your reply at appropriate point(s) in previous post. Thanks.> Well > > I have two non related models, but I need to update an attribute value > of one model using a value from the other one. I''ve tried using > callbacks(after_create update_attribute), but it didn''t work because > they are not related and because I need "extra" conditions. So I think > I could solve this using a raw sql queryHaving a value in one table dependent on the value in another is often a sign of non-optimal database design. Are you sure that this could not be improved? Even if that is the best solution I don''t see why that requires raw sql, or why it could not be done in a callback. Colin> > On Aug 9, 3:43 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 9 August 2011 18:34, Angelo Cordova <acord...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > Hi people >> >> > I need to write a raw sql query in rails 3. But I don''t know where >> > should I do this, in the model or in the controller? >> >> If you are not sure where it should be then firstly I would ask >> whether you are sure you need to write a raw sql query. If you do >> need to do that then almost always it should be in a model. However >> without knowing more details of what it does and why, it is impossible >> to give an absolute answer. >> >> Colin > > -- > 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@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.