From e397a61096f0e3194dab3c8d4d23959bb998df4d Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 10 Mar 2022 10:31:16 +0100 Subject: [PATCH] Relation model superclass work --- src/db_models.rb | 15 +++++++++++++++ src/lib/database.rb | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/db_models.rb b/src/db_models.rb index fbeecad..ab2d98d 100644 --- a/src/db_models.rb +++ b/src/db_models.rb @@ -193,6 +193,14 @@ class Category < EntityModel @name = data["name"] @color = data["color"] end + + def self.create(name, color) + data = { + name: name, + color: color + } + self.insert(data) + end end class Image < EntityModel @@ -212,5 +220,12 @@ class Auction_Category_relation < EntityModel @auction_id = data["auction_id"] @category_id = data["category_id"] end + + def self.get_user_roles(user_id) + roleids = self.get "role_id", "user_id = ?", user_id + roles = roleids.map do |ent| + Role.find_by_id(ent["role_id"].to_i) + end + end end diff --git a/src/lib/database.rb b/src/lib/database.rb index 455effd..98e8bdc 100644 --- a/src/lib/database.rb +++ b/src/lib/database.rb @@ -72,3 +72,15 @@ class EntityModel end end end + +class RelationModel < EntityModel + def self.table1 = nil + def self.table2 = nil + + def self.get_relation(id) + roleids = self.get "role_id", "user_id = ?", user_id + roles = roleids.map do |ent| + Role.find_by_id(ent["role_id"].to_i) + end + end +end