Hi, I have a User class with many projects : has_many :projects, :through=>:membership, :select => "memberships.active, projects.*" The active field in the memberships table is an int. So why this works : def active_projects projects.select{|p| p.active==''1''}.sort_by {|p| [p.name.upcase]} end while this does not : def active_projects projects.select{|p| p.active==1}.sort_by {|p| [p.name.upcase]} end The difference is just that I compare with an integer instead of a string in the first case. I was expecting p.active to be a integer, not a string. Thanks, Mickael. -- 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 -~----------~----~----~----~------~----~------~--~---
On 9 Dec 2008, at 22:30, Mickael Faivre-Macon wrote:> > Hi, > > I have a User class with many projects : > > has_many :projects, :through=>:membership, :select => > "memberships.active, projects.*" > > The active field in the memberships table is an int. > > So why this works : > > def active_projects > projects.select{|p| p.active==''1''}.sort_by {|p| [p.name.upcase]} > end > > while this does not : > > def active_projects > projects.select{|p| p.active==1}.sort_by {|p| [p.name.upcase]} > end > > The difference is just that I compare with an integer instead of a > string in the first case. I was expecting p.active to be a integer, > not > a string. >When you pick attributes not from the base table (in this case projects) rails will handle things as strings. Maybe not what one would hope for, but it''s the way things are right now. Fred> Thanks, > Mickael. > -- > 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 -~----------~----~----~----~------~----~------~--~---
No problem, I''ll do with it :) Thanks for this explanation. MIckael. Frederick Cheung wrote:> When you pick attributes not from the base table (in this case > projects) rails will handle things as strings. Maybe not what one > would hope for, but it''s the way things are right now. > > Fred-- 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 -~----------~----~----~----~------~----~------~--~---