Relation model superclass work

master
E. Almqvist 3 years ago
parent ef8f154026
commit e397a61096
  1. 15
      src/db_models.rb
  2. 12
      src/lib/database.rb

@ -193,6 +193,14 @@ class Category < EntityModel
@name = data["name"] @name = data["name"]
@color = data["color"] @color = data["color"]
end end
def self.create(name, color)
data = {
name: name,
color: color
}
self.insert(data)
end
end end
class Image < EntityModel class Image < EntityModel
@ -212,5 +220,12 @@ class Auction_Category_relation < EntityModel
@auction_id = data["auction_id"] @auction_id = data["auction_id"]
@category_id = data["category_id"] @category_id = data["category_id"]
end 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 end

@ -72,3 +72,15 @@ class EntityModel
end end
end 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

Loading…
Cancel
Save