v3 add _type_disabled to ovveride activerecord setting wrong class on job

This commit is contained in:
carlad 2015-08-26 16:33:16 +02:00
parent 98bcc9e530
commit 1a3d42da21
4 changed files with 11 additions and 5 deletions

View File

@ -5,7 +5,11 @@ module Travis::API::V3
belongs_to :request
belongs_to :repository, autosave: true
belongs_to :owner, polymorphic: true
has_many :jobs, as: :source, order: :id, dependent: :destroy
has_many :jobs,
as: :source,
order: :id,
dependent: :destroy
has_one :branch,
foreign_key: [:repository_id, :name],

View File

@ -1,5 +1,8 @@
module Travis::API::V3
class Models::Job < Model
self.inheritance_column = :_type_disabled
has_one :log, dependent: :destroy
belongs_to :repository
belongs_to :commit

View File

@ -48,6 +48,7 @@ module Travis::API::V3
when Time then value.strftime('%Y-%m-%dT%H:%M:%SZ')
when Model then render_model(value, **options)
when ActiveRecord::Relation then render_value(value.to_a, **options)
when ActiveRecord::Associations::CollectionProxy then render_value(value.to_a, **options)
else raise ArgumentError, 'cannot render %p (%p)' % [value.class, value]
end
end

View File

@ -2,9 +2,7 @@ require 'travis/api/v3/renderer/model_renderer'
module Travis::API::V3
class Renderer::Job < Renderer::ModelRenderer
# # representation(:minimal, :id, :number, :state, :queue, :type, :started_at, :finished_at)
# representation(:minimal, :id)
# # representation(:standard, *representations[:minimal], :repository_id, :commit_id, :source_type, source_id)
# representation(:standard, *representations[:minimal])
representation(:minimal, :id, :number, :state, :started_at, :finished_at)
representation(:standard, *representations[:minimal], :build, :queue, :repository, :commit, :owner )
end
end