Merge pull request 'Update API DB oriented models' init functions' (#92) from better-db-inits into main
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: mentorenwahl/mentorenwahl#92
This commit is contained in:
commit
4bf65a4d87
|
@ -36,8 +36,8 @@ module Backend
|
|||
def initialize(@model : {{ type }})
|
||||
end
|
||||
|
||||
def initialize(id : Int32)
|
||||
@model = {{ type }}.find!(id)
|
||||
def self.from_id(id : Int32) : self
|
||||
new({{ type }}.find!(id))
|
||||
end
|
||||
|
||||
{% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %}
|
||||
|
|
|
@ -38,7 +38,7 @@ module Backend
|
|||
def user(context : Context, id : Int32) : User
|
||||
context.admin!
|
||||
|
||||
User.new(id)
|
||||
User.from_id(id)
|
||||
end
|
||||
|
||||
@[GraphQL::Field]
|
||||
|
|
|
@ -76,7 +76,7 @@ module Backend
|
|||
end
|
||||
|
||||
# Creates user data from DB entry index
|
||||
def self.from_index(id : Int32) : self
|
||||
def self.from_id(id : Int32) : self
|
||||
from_db(Db::User.find!(id))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue