Hi all, I am creating a table that defines permissions to certain group or person. Classes class Report_membership < ActiveRecord::Base belongs_to :member, :foreign_key => :member_id, :class_name => ''Person'' belongs_to :member, :foreign_key => :member_id, :class_name => ''Group'' end Class Group < ActiveRecord::Base has_many :report_memberships, :foreign_key => :member_id end Class Person < ActiveRecord::Base has_many :report_memberships, :foreign_key => :member_id end This Builds the reverse associations okay, and will display all the groups. If i switch the belongs_to order in the report_membership class then it will display all of the people that I have. Before I save the record I was going to append to the value a 1 if it was a group or a 0 if it was a person, so the first record of the group would be 11 , and 21 the second and the 1st person would be 10 and the second would be 20. The only way I can complete it this was is if there is a way I can manually write the sql for options_for_association_conditions method in the helper method, and I haven''t found a way to do that. If there is a known way to do this, different from this, please educate me White Wizzard --~--~---------~--~----~------------~-------~--~----~ 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 27 Nov 2007, at 20:30, White Wizzard wrote:> > Hi all, > > I am creating a table that defines permissions to certain group or > person. > > Classes > class Report_membership < ActiveRecord::Base > belongs_to :member, :foreign_key => :member_id, :class_name => > ''Person'' > belongs_to :member, :foreign_key => :member_id, :class_name => > ''Group'' > end > Class Group < ActiveRecord::Base > has_many :report_memberships, :foreign_key => :member_id > end > Class Person < ActiveRecord::Base > has_many :report_memberships, :foreign_key => :member_id > end > > This Builds the reverse associations okay, and will display all the > groups. If i switch the belongs_to order in the report_membership > class then it will display all of the people that I have. > > Before I save the record I was going to append to the value a 1 if it > was a group or a 0 if it was a person, so the first record of the > group would be 11 , and 21 the second and the 1st person would be 10 > and the second would be 20. >That''s a really bad idea. Either have separate person_id/group_id columns, or use polymorphic associations (which is sort of what you''re cobbling together) Fred> The only way I can complete it this was is if there is a way I can > manually write the sql for options_for_association_conditions method > in the helper method, and I haven''t found a way to do that. > > If there is a known way to do this, different from this, please > educate me > > White Wizzard > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
HI Fred Yes polymorphic associations would work but do to the work environment I am in, I don'' t think it is a good Idea because it hard codes the class strings. My superior Every so often decides that a class name needs to be changed and he doesn''t like to modify data that is in existence. When I get something working, It gets uploaded to the server and he goes and reviews all the changes ( I know how bad that is). My solution would be to have the type be a one or a zero but I don''t know how to get that to work, as active record does most of the work with polymorphic associations. The other thing that need to worry about is that I am constrained to use Active Scaffold for ALL of the views, with the exception of the login and the home page. If you know a way to have the type be a integer that I can enumerate, This will work, but if I can''t do that It could possibly create a large amount of work in the future. White Wizzard --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ugh. Painful. But, can you use before_save on the model with the value? On Nov 28, 2007 12:34 PM, White Wizzard <The.White.Wizzard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > HI Fred > > Yes polymorphic associations would work but do to the work environment > I am in, I don'' t think it is a good Idea because it hard codes the > class strings. My superior Every so often decides that a class name > needs to be changed and he doesn''t like to modify data that is in > existence. When I get something working, It gets uploaded to the > server and he goes and reviews all the changes ( I know how bad that > is). My solution would be to have the type be a one or a zero but I > don''t know how to get that to work, as active record does most of the > work with polymorphic associations. The other thing that need to > worry about is that I am constrained to use Active Scaffold for ALL of > the views, with the exception of the login and the home page. > > If you know a way to have the type be a integer that I can enumerate, > This will work, but if I can''t do that It could possibly create a > large amount of work in the future. > > > White Wizzard > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---