From e7c2706f3b6e3f30aceece313d8db4abb622b275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tollk=C3=BChn?= Date: Mon, 21 Jul 2025 14:35:10 +0200 Subject: [PATCH] ensure to not duplicate clients --- app/models/subproject.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/models/subproject.rb b/app/models/subproject.rb index 6b140a1..c943d2d 100644 --- a/app/models/subproject.rb +++ b/app/models/subproject.rb @@ -14,6 +14,21 @@ class Subproject < ApplicationRecord validate :owner_presence_check validate :builder_presence_check + def client_attributes=(attributes) + self.client = Client.find_or_initialize_by(email: attributes[:email]) + self.client.assign_attributes(attributes) + end + + def owner_attributes=(attributes) + self.owner = Client.find_or_initialize_by(email: attributes[:email]) + self.owner.assign_attributes(attributes) + end + + def builder_attributes=(attributes) + self.builder = Client.find_or_initialize_by(email: attributes[:email]) + self.builder.assign_attributes(attributes) + end + private def client_presence_check