Sumit Srivastava
2013-Mar-14 10:12 UTC
Rails adding computed field to a join of multiple tables
I did join on three tables. arel = OfferOrder.includes(:a, :b, :c) arel = arel.select(''(CASE WHEN ISNULL(c.field2) THEN c.field1 ELSE c.field2 END) AS fraud'') but when I run my code it gives error that (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''AS fraud) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/HNyCdaXFyX4J. For more options, visit https://groups.google.com/groups/opt_out.
Sumit Srivastava
2013-Mar-14 10:16 UTC
Re: Rails adding computed field to a join of multiple tables
Also I did try it this way, arel = OfferOrder.includes(:a, :b).joins(:c).select(''(CASE WHEN ISNULL(c.fields2) THEN c.fields1 ELSE c.field2 END) '') Got error, ActiveModel::MissingAttributeError (missing attribute: a_id): I did join on three tables.> > arel = OfferOrder.includes(:a, :b, :c) arel = arel.select(''(CASE WHEN > ISNULL(c.field2) THEN c.field1 ELSE c.field2 END) AS fraud'') > > but when I run my code it gives error that > > (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''AS fraud) > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ifFqk0WyB9YJ. For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists
2013-Mar-15 11:11 UTC
Re: Re: Rails adding computed field to a join of multiple tables
On Thu, Mar 14, 2013 at 5:16 AM, Sumit Srivastava <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Also I did try it this way, > > arel = OfferOrder.includes(:a, :b).joins(:c).select(''(CASE WHEN > ISNULL(c.fields2) THEN c.fields1 ELSE c.field2 END) '') > > Got error, > > ActiveModel::MissingAttributeError (missing attribute: a_id): > > > > > I did join on three tables. >> >> arel = OfferOrder.includes(:a, :b, :c) arel = arel.select(''(CASE WHEN >> ISNULL(c.field2) THEN c.field1 ELSE c.field2 END) AS fraud'') >> >> but when I run my code it gives error that >> >> (Mysql2::Error: You have an error in your SQL syntax; check the manual >> that corresponds to your MySQL server version for the right syntax to use >> near ''AS fraud) >What was the SQL it generated? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
sumit srivastava
2013-Mar-15 11:15 UTC
Re: Re: Rails adding computed field to a join of multiple tables
On 15 March 2013 16:41, tamouse mailing lists <tamouse.lists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> On Thu, Mar 14, 2013 at 5:16 AM, Sumit Srivastava > <sumit.theinvincible-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Also I did try it this way, > > > > arel = OfferOrder.includes(:a, :b).joins(:c).select(''(CASE WHEN > > ISNULL(c.fields2) THEN c.fields1 ELSE c.field2 END) '') > > > > Got error, > > > > ActiveModel::MissingAttributeError (missing attribute: a_id): > > > > > > > > > > I did join on three tables. > >> > >> arel = OfferOrder.includes(:a, :b, :c) arel = arel.select(''(CASE WHEN > >> ISNULL(c.field2) THEN c.field1 ELSE c.field2 END) AS fraud'') > >> > >> but when I run my code it gives error that > >> > >> (Mysql2::Error: You have an error in your SQL syntax; check the manual > >> that corresponds to your MySQL server version for the right syntax to > use > >> near ''AS fraud) > > > > What was the SQL it generated? >Resolved this. Had to defined the join conditions and it worked. Though am stuck on another. The select query is not working when another query is made using <<SQL tags in the code. Can''t avoid using those. Regards Sumit Srivastava The power of imagination makes us infinite...> > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/rubyonrails-talk/xH1LYbHTIIU/unsubscribe?hl=en-US > . > To unsubscribe from this group and all its topics, send an email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.