app/models/contact.rb in e9_crm-0.1.12 vs app/models/contact.rb in e9_crm-0.1.13
- old
+ new
@@ -82,12 +82,16 @@
clear_primary :save => true
end
end
accepts_nested_attributes_for :users, :allow_destroy => true
- delegate :email, :to => 'users.primary.first', :allow_nil => true
+ def primary_user
+ users.primary.first
+ end
+ delegate :email, :to => :primary_user, :allow_nil => true
+
def page_views
PageView.by_user(users)
end
has_many :record_attributes, :as => :record
@@ -299,10 +303,17 @@
def _assign_initialization_defaults
self.status ||= Status::Contact
end
def ensure_user_references
- users.each {|u| u.contact = self }
+ users.each {|u|
+ # We set contact as self on all our users so they have a reference to the contact.
+ # This doesn't happen with nested associations by default.
+ u.contact = self
+
+ # make sure our users have our first name if it's blank
+ u.first_name = self.first_name if u.first_name.blank?
+ }
end
# override has_destroy_flag? to force destroy on persisted associations as well
def has_destroy_flag?(hash)
reject_record_attribute?(hash) || super