I have Advertisements which can have ladyies, but only if the type is a “club”.
Is there a rails-way to do that? especially with not creating lady objects?
Do I have to check a lady object, before creating, if her parent is type=club?
class Advertisement < ActiveRecord::Base
validates_inclusion_of :type, in: %w(club lady)
has_many :ladies, :dependent=>:destroy
#only have ladies if the club =
def ladies
return nil unless type == "club"
super
end
end
I’m using Rails 3.2.
The Rails way to do that is STI:
And only LadyAd object able to have ladies.