-
Notifications
You must be signed in to change notification settings - Fork 335
Description
I'm not sure what the actual change was that made this occur, as I didn't see anything in the CHANGELOG that indicated that this behavior should have even happened, so I wanted to mention it here in the issue log so that the author was aware.
I have a table using Single Table Inheritance (STI) in my Rails project, and the way that the label of the 'root' object for the associations between the objects changed in a way that broke our API after upgrading from RABL 0.8.6 to 0.9.0.
Here is the ActiveRecord setup:
# Parent class
# == Schema Information
#
# Table name: nodes
#
# id :integer not null, primary key
# title :string(255)
# description :text
# pos :integer
# type :string(255)
# parent_id :integer
class Node < ActiveRecord::Base
end
class Unit < Node
has_many :sections, :foreign_key => :parent_id, :inverse_of => :parent, :dependent => :destroy
alias_method :children, :sections
end
class Section < Node
belongs_to :parent, :class_name => 'Unit', :inverse_of => :sections
endHere is the setup for the RABL view template:
# views/api/unit.json.rabl
object @unit
attributes :id, :type, :pos, :title, :description
child(:sections) do
attributes :id, :type, :pos, :title, :description
endWith RABL 0.8.6, the output would look like this:
{
id: 1,
type: 'Unit',
pos: 1,
title: 'A Unit',
description: 'Sample Desc.',
sections: [
{
id: 2,
type: 'Section',
pos: 1,
title: 'A Section',
description: 'blah',
}
]
}After upgrading RABL to 0.9.0, the output changed so that the label for the root node of the sections group, was now labeled 'nodes' instead of 'sections' like so:
{
id: 1,
type: 'Unit',
pos: 1,
title: 'A Unit',
description: 'Sample Desc.',
nodes: [
{
id: 2,
type: 'Section',
pos: 1,
title: 'A Section',
description: 'blah',
}
]
}We made no change to the RABL view template, so this is a change in the way the gem behaves when handling associations that have STI like the above example. I was able to get it to revert to the 0.8.6 behavior by changing the line in the view file from this:
child(:sections) doto this:
child(:sections => :sections) doNot a huge deal at the end of the day, but because there didn't seem to be anything mentioning this change in behavior on the CHANGELOG, ran into it unexpectedly and it briefly broke our API while we figured out what was going on here. Not sure if this behavior change was intentional or not, but I figured I should mention it here so you could either list this in your 'Breaking Changes' section on the README or at least in the CHANGELOG. Great gem btw!