I have a model Artboard and a model Group that has a many to many relationship through a table called ArtboardsGroups that has attributes for an x and y value pertaining to the relationship
class Artboard < ApplicationRecord
has_many :artboards_groups, dependent: :destroy
has_many :groups, -> { select("groups.id as id, groups.name as name, artboards_groups.x as x, artboards_groups.y as y, artboards_groups.index as index, artboards_groups.r as r") }, through: :artboards_groups
end
class ArtboardsGroup < ApplicationRecord
belongs_to :artboard
belongs_to :group
end
class Group < ApplicationRecord
has_many :artboards_groups, dependent: :destroy
has_many :artboards, through: :artboards_group
end
The model works perfectly fine when I try to access it by itself but when I try to select groups through an artboard and access the 'y' attribute I get a error that it is a private method
NoMethodError: private method `y' called for #<Group id: 5, name: nil>
According to this thread (From over 10 years ago) it is because there is a private method in ActiveRecord::Base called 'y' /lib/ruby/2.5.0/psych/y.rb which is from a gem called psych that is a yaml parser
I don't want to change the attribute name for 'y' considering it is referencing a coordinate system and (x,y) is the standard for coordinates. Is there any other way to deal with this?