Tricky form validation

Hi list,

I want to create a form validation in my Marketing Model.
I want to raise an error only if a previous marketing campaign for a
property has not been completed (ie. ended_on IS NULL)

I managed to get this working in the Controller using something this:

if Marketing.count(“property_id = #{@marketing.property_id} AND ended_on
IS NULL”) > 0

However I assume validation should be in the Model so this is where I am
stuck… I am guessing ill have to use validates_uniqueness_of with a
:if => ‘???’

any ideas?

Brendon G. wrote:

SOLVED!
(Model)
def validate_on_create
if Marketing.count(“property_id = #{property_id} AND ended_on IS NULL”)

0
errors.add(“property_id”,“is already being marketed, first end the
current campaign.”)
end
end