From 4aee2c3b45caa890537a0fc0c850c4523a4eb56c Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Sat, 6 Apr 2024 18:45:49 +0200
Subject: model: CRUD methods only for targeted objects

A create, read, update or delete (CRUD) method should only care about
the object which provides the receiver and the relations to its child
objects.

For example the method

	func (r *Recipe) Create(tx *sql.Tx) error {}

should only create the relational data inside the database for the
recipe, not for the steps nested into this Recipe struct. This should be
covered by the

	func (s *Step) Create(tx *sql.Tx) error {}

method which is then called by `func (r *Recipe) Create()`.

This has the advantage that every CRUD method has a constraint scope and
is more unified since the Step CRUD methods now have a Step struct as
receiver instead of a Recipe receiver.
---
 model/sql/migrate.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'model/sql/migrate.sql')

diff --git a/model/sql/migrate.sql b/model/sql/migrate.sql
index 9577dab..f931af6 100644
--- a/model/sql/migrate.sql
+++ b/model/sql/migrate.sql
@@ -12,8 +12,8 @@ CREATE TABLE recipes (
 
 CREATE TABLE steps (
 	id      INTEGER PRIMARY KEY,
-	recipe  INTEGER NOT NULL,
 	'index' INTEGER NOT NULL,
 	text    TEXT    NOT NULL,
+	recipe  INTEGER NOT NULL,
 	FOREIGN KEY(recipe) REFERENCES recipes(id)
 );
-- 
cgit v1.2.3-70-g09d2

