I would like to use only one table ads on database. regular AD:> :title > :price > :content > :username > > trip AD: > :title > :price > :content > :username > :from > :to >Which associations should I use? Polymorphic Associations The has_and_belongs_to_many Else? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/qX_0b5u_P4oJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I create a Gist with my recent ideas: https://gist.github.com/1770515 ** <http://groups.google.com/group/rubyonrails-talk?hl=pl> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/sl97xZWm1WAJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
what are the other objects? What is it that has_and_belongs_to_many? for polymorphic relationships you want to ask if more than one So class Ad belongs_to :adable, :polymorphic => true end class Customer has_many :ads, :as => :adable end class NewsPaper has_many :ads, :as=>:adable end At least I think this is what you are looking for. Maybe some others will give advice. On Feb 8, 10:40 am, regedarek <dariusz.fins...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I create a Gist with my recent ideas:https://gist.github.com/1770515 > ** <http://groups.google.com/group/rubyonrails-talk?hl=pl>-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
STI , Single Table Inheritance (This structure is best used for models that have identical, or very similar attributes ) trip AD << regular AD class RegularAd < ActiveRecord::Base end class TripAd < RegularAd end migration (Rails 3.1) class CreateAds < ActiveRecord::Migration def change create_table(:regular_ads) do |t| t.string : title t.float : price t.string : content t.string : username t.integer : from t.integer: to end end end On Feb 8, 6:10 pm, regedarek <dariusz.fins...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I would like to use only one table ads on database. > > regular AD: > > > :title > > :price > > :content > > :username > > > trip AD: > > :title > > :price > > :content > > :username > > :from > > :to > > Which associations should I use? > Polymorphic Associations > The has_and_belongs_to_many > Else?-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think form me i should be something like this below because I need different validations to each type of ads. Or in your example could i set up this kind of different validations?> class Ad < ActiveRecord::Base > validates_presence_of :name, :email, :price(?), :category_id(?) > > :name > :phone_number > :email > :advertiser_id > :token > :verification_date > :level > :category_id > :admin_id > :price > :display_counter > :type > end >class RegularAd < Ad> validates_presence_of :title, :ad_content > > :title > :ad_content > end >class RideAd < Ad> validates_presence_of :from, :to > > :from > :to > end >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/IFi12eQy7hYJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.