blob: 790fef7720c03ed4e7c1def64eab5e401ab655b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
Target.transaction do
wanted = {
"salades" => 40,
"tomates général" => 40,
"développement floral" => 20
}
# Ensure all referenced profiles exist
profiles = NutrientProfile.where(name: wanted.keys).index_by(&:name)
missing = wanted.keys - profiles.keys
raise "Missing NutrientProfile(s): #{missing.join(', ')}" if missing.any?
target = Target.find_or_create_by!(name: "Objectif par défaut")
target.target_allocations.destroy_all
wanted.each do |name, pct|
target.target_allocations.build(nutrient_profile: profiles[name], percentage: pct)
end
target.save!
end
|