Hi I have the following tables Ads - contains ads by people Options - contains options (all are yes or no like a check box) for each ad; examples (assuming it is a car ad) Air_condition, Auto_Transmission, Keyless_entry, etc. Each option will have a yes or no value. the table ad_options will contain actual values for each ad for the option; class Ad < ActiveRecord::Base has_many :options, :through => :ad_options end Is the above statement correct? if yes how can I use the mtm relationship in views to show and update options. This will give me the flexibility to add options without changing the code. Thanks a lot for your help rt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-09 02:51 UTC
Re: Many to Many questions
How many tables do you have and what columns have you defined in it? Without knowing what data you are capturing it is not possible to check if what you are doing is correct. You can show the options as check boxes that users can select if they want. This will be under the ad that they want to create. On Mar 8, 4:54 pm, "rubyonrails" <rajads...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Hi > I have the following tables > > Ads - contains ads by people > Options - contains options (all are yes or no like a check box) for > each ad; examples (assuming it is a car ad) Air_condition, > Auto_Transmission, Keyless_entry, etc.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-09 10:05 UTC
Re: Many to Many questions
Presumably, you would want to have an ad_types table... otherwise, what''s the point in an ad having an "air conditioning" option when it''ll be false? So, assuming I''ve understood correctly: Ad belongs_to :ad_type has_many :options, :through => values end AdType has_many :ads has_many :options # (or maybe habtm would be better) end Option belongs_to :ad_type has_many :values has_many :ads, :through => :values end Value belongs_to :option belongs_to :ad end You''re options table would contain the strings such as "air conditioning", and the values would contain the boolean value of an option for it''s ad. I think I''ve covered everything there. That''s the best way I can think of to do what you''re trying to do. There''s a loop in the table relationships, which might cause a few problems in writing the model, but nothing that can''t be solved with a bit of work. For example, an ad must have the same options when going round one way as when going the other way. You''re model should make sure that this integrity is maintained. Hope this helps. If anyone reckons this is completely the wrong way of doing it, please say so. -N On 08/03/07, rubyonrails <rajads133-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > > Hi > I have the following tables > > Ads - contains ads by people > Options - contains options (all are yes or no like a check box) for > each ad; examples (assuming it is a car ad) Air_condition, > Auto_Transmission, Keyless_entry, etc. > > Each option will have a yes or no value. > > the table ad_options will contain actual values for each ad for the > option; > > class Ad < ActiveRecord::Base > has_many :options, :through => :ad_options > end > > Is the above statement correct? if yes how can I use the mtm > relationship in views to show and update options. This will give me > the flexibility to add options without changing the code. > > Thanks a lot for your help > rt > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---