Chris Hall
2005-Dec-14 15:11 UTC
why would an int column in a join table be a String class in model?
i''ve got an issue with integer columns in the database becoming strings in the model and I''m not sure why this is happening. perhaps someone can explain. given the following setup (simplified for example) tables: users ---------- id - int name - varchar(60) roles ---------- id - int name - varchar(60) roles_users (join table) ---------- role_id - int user_id - int default_flag - int data: user => 1, ''joe'' role => 1, ''admin'' roles_users => 1, 1, 1 models: class User < ActiveRecord::Base has_and_belongs_to_many :roles end class Role < ActiveRecord::Base has_and_belongs_to_many :users end console:>> user = User.find(1)=> #<User:0xb771b494 @attributes={"id"=>"1", "location_id"=>nil, "active_flag"=>"1", "name"=>"joe"}>>> user.roles[0].default_flag.class=> String>> user.roles[0].id.class=> Fixnum shouldn''t default_flag be a Fixnum? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Wilson Bilkovich
2005-Dec-14 21:32 UTC
Re: why would an int column in a join table be a String class in model?
On 12/14/05, Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i''ve got an issue with integer columns in the database becoming strings in > the model and I''m not sure why this is happening. perhaps someone can > explain.<snip> Is this possibly the same issue as this ticket? http://dev.rubyonrails.org/ticket/240 --Wilson.
Chris Hall
2005-Dec-15 01:59 UTC
Re: why would an int column in a join table be a String class in model?
thanks. sometimes i forget to go look at trac. yes, it looks to be the same...i see a fix has been pushed back to 1.x...noproblem, i can always do == "1" in the meantime. On 12/14/05, Wilson Bilkovich <wilsonb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 12/14/05, Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > i''ve got an issue with integer columns in the database becoming strings > in > > the model and I''m not sure why this is happening. perhaps someone can > > explain. > <snip> > > Is this possibly the same issue as this ticket? > http://dev.rubyonrails.org/ticket/240 > > --Wilson. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Rabbit
2005-Dec-15 02:39 UTC
Re: why would an int column in a join table be a String class in model?
to_i also works. :) On 12/14/05, Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thanks. sometimes i forget to go look at trac. > > yes, it looks to be the same...i see a fix has been pushed back to 1.x...no > problem, i can always do == "1" in the meantime. > > > On 12/14/05, Wilson Bilkovich <wilsonb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 12/14/05, Chris Hall < christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > i''ve got an issue with integer columns in the database becoming strings > in > > > the model and I''m not sure why this is happening. perhaps someone can > > > explain. > > <snip> > > > > Is this possibly the same issue as this ticket? > > http://dev.rubyonrails.org/ticket/240 > > > > --Wilson. > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >