24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/erp_base_erp_svcs/extensions/active_record/has_contacts.rb', line 24
def find_by_email(email, contact_purpose=nil)
if contact_purpose
self.joins(:contacts => [:contact_purposes])
.joins("INNER JOIN email_addresses on email_addresses.id = contacts.contact_mechanism_id
and contacts.contact_mechanism_type = 'EmailAddress'")
.where('contact_mechanism_type = ?', 'EmailAddress')
.where('contact_purposes.internal_identifier = ?', contact_purpose)
.where('email_address = ?', email).readonly(false).first
else
self.joins(:contacts)
.joins("INNER JOIN email_addresses on email_addresses.id = contacts.contact_mechanism_id
and contacts.contact_mechanism_type = 'EmailAddress'")
.where('contact_mechanism_type = ?', 'EmailAddress')
.where('email_address = ?', email).readonly(false).first
end
end
|