validations
This commit is contained in:
		| @@ -3,8 +3,8 @@ class Client < ApplicationRecord | |||||||
|   has_many :owner_subprojects, class_name: 'Subproject', foreign_key: 'owner_id' |   has_many :owner_subprojects, class_name: 'Subproject', foreign_key: 'owner_id' | ||||||
|   has_many :builder_subprojects, class_name: 'Subproject', foreign_key: 'builder_id' |   has_many :builder_subprojects, class_name: 'Subproject', foreign_key: 'builder_id' | ||||||
|  |  | ||||||
|   validates :company_name, :firstname, :lastname, presence: true |   validates :company_name, :firstname, :lastname, :email, presence: true | ||||||
|   validates :email, presence: true, uniqueness: true |   validates :email, uniqueness: true | ||||||
|  |  | ||||||
|   def referenced_count |   def referenced_count | ||||||
|     owner_subprojects.count + builder_subprojects.count + client_subprojects.count |     owner_subprojects.count + builder_subprojects.count + client_subprojects.count | ||||||
|   | |||||||
| @@ -14,6 +14,8 @@ class Subproject < ApplicationRecord | |||||||
|   validate :owner_presence_check |   validate :owner_presence_check | ||||||
|   validate :builder_presence_check |   validate :builder_presence_check | ||||||
|  |  | ||||||
|  |   validates_associated :client, :owner, :builder | ||||||
|  |  | ||||||
|   def client_attributes=(attributes) |   def client_attributes=(attributes) | ||||||
|     self.client = Client.find_or_initialize_by(email: attributes[:email]) |     self.client = Client.find_or_initialize_by(email: attributes[:email]) | ||||||
|     self.client.assign_attributes(attributes) |     self.client.assign_attributes(attributes) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Stefan Tollkühn
					Stefan Tollkühn