Hi, I have a table in database which has description of all the statuses that an account can have and their flag values, like 0 means unapproved, 1 meanns approved, 3 means suspended and so on. Now, when I am inserting an account record or updating then how do I get the value from this status table if I want flag value for apprroved or suspended etc.? Basically, how do I know that I have to set flag to 0, 1 or 2 for approved? thanks. -- 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 -~----------~----~----~----~------~----~------~--~---
>From what I can gather it sounds like you have a user table that mightlook like this. Of course it could have a lot more columns as well...but these are the ones you seem to be dealing with. ------------------------------------------------------------------ |user_id | approved | unapproved | suspended | |-----------------------------------------------------------------| | 23 | 1 | 0 | 0 | |_____________________________________| why do you need a 2nd table? Just read the property directly from the users table. You''d be duplicating data if you add another table and slowing down mysql by needing to join. Maybe I''m wrong or misunderstood, but that seems like it would work to me. -Jon On Mar 8, 12:16 pm, Rm Rm <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I have a table in database which has description of all the statuses > that an account can have and their flag values, like 0 means unapproved, > 1 meanns approved, 3 means suspended and so on. Now, when I am inserting > an account record or updating then how do I get the value from this > status table if I want flag value for apprroved or suspended etc.? > Basically, how do I know that I have to set flag to 0, 1 or 2 for > approved? > > thanks. > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
What I have is a user table like : id name status this status could be 0 for pending, 1 for approved, 2 for hold etc. And there is another table as statuses: id value desc with row data as : 1,0,Pending 2,1,Approved 3,2,Hold ... Now how do I use this status table if I want to create an user record with approved status? kinneyjd wrote:>>From what I can gather it sounds like you have a user table that might > look like this. Of course it could have a lot more columns as > well...but these are the ones you seem to be dealing with. > > ------------------------------------------------------------------ > |user_id | approved | unapproved | suspended | > |-----------------------------------------------------------------| > | 23 | 1 | 0 | 0 | > |_____________________________________| > > why do you need a 2nd table? > > Just read the property directly from the users table. You''d be > duplicating data if you add another table and slowing down mysql by > needing to join. > > Maybe I''m wrong or misunderstood, but that seems like it would work to > me. > -Jon-- 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 -~----------~----~----~----~------~----~------~--~---
User.create({ :name => ''joe'', :status => Status.find_by_name(''Approved'').value })? It might be better if you removed the ''value'' column from the Status model and then use a has_one relationship from User to Status: # statuses(id, status_name) class Status < ActiveRecord::Base end # users(id, name, status_id) class User < ActiveRecord::Base has_one :status end>> User.create({:name => ''joe'', :status => Status.find_by_name(''Approved'') }) >> User.find(:all, :include => :status).map(&:status_name)On Mar 9, 9:22 am, Rm Rm <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> What I have is a user table like : > > id > name > status > > this status could be 0 for pending, 1 for approved, 2 for hold etc. > > And there is another table as statuses: > id > value > desc > > with row data as : > > 1,0,Pending > 2,1,Approved > 3,2,Hold > > ... > > Now how do I use this status table if I want to create an user record > with approved status? > > > > kinneyjd wrote: > >>From what I can gather it sounds like you have a user table that might > > look like this. Of course it could have a lot more columns as > > well...but these are the ones you seem to be dealing with. > > > ------------------------------------------------------------------ > > |user_id | approved | unapproved | suspended | > > |-----------------------------------------------------------------| > > | 23 | 1 | 0 | 0 | > > |_____________________________________| > > > why do you need a 2nd table? > > > Just read the property directly from the users table. You''d be > > duplicating data if you add another table and slowing down mysql by > > needing to join. > > > Maybe I''m wrong or misunderstood, but that seems like it would work to > > me. > > -Jon > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Eden Li wrote:> # statuses(id, status_name) > class Status < ActiveRecord::Base > end > > # users(id, name, status_id) > class User < ActiveRecord::Base > has_one :status > end > >>> User.create({:name => ''joe'', :status => Status.find_by_name(''Approved'') }) >>> User.find(:all, :include => :status).map(&:status_name)It''s actually belongs_to, which goes where the FK is. Status has_many Users, User belongs_to Status. A. -- 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 -~----------~----~----~----~------~----~------~--~---