mercredi 13 septembre 2017

How to pass argument value to has_one association from method

I have a method in lib folder. Now I need to send a value to has_one which is different model

Example:

lib/acord.rb

def total_pages_of_form_version(form_version)
  form_version.form.check_overflow_form(self.original_effective_date)
end

form.rb

has_one :check_overflow_form, -> (policy_effective_date) { where 'expiration_date >= ? or expiration_date IS NULL', policy_effective_date}, class_name: 'Form', foreign_key: 'parent_form_id', dependent: :destroy

When I run the query, I am getting

Form Load (44.1ms) SELECT forms.* FROM forms WHERE forms.parent_form_id = 18338 AND (expiration_date >= 18338 or expiration_date IS NULL) LIMIT 1

Above query in place of expiration_date it is fetching form_id (18338) but I need to get original_effective_date value

Aucun commentaire:

Enregistrer un commentaire