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