I have an issue calling objects within an array of ActiveRecord objects.
Here is my controller code building an array of things:
onething = Thing.where(this: id, that: id)
@things.push(onething) if onething.present?
This is looped in order to build an array of specific things with different ids passed inside the where method for this and that.
This and That being parents from thing:
class Thing < ApplicationRecord
belongs_to :this
belongs_to :that
end
Though in my view, when I call elements of the @things variable I get undefined methods errors.
When showing the @things variable in my view, in order to debug, I get things like this:
[#<ActiveRecord::Relation [#<Thing id: 1 ....>]>, #<ActiveRecord::Relation [#<Thing id: 2.......>]>]
Whereas, a variable with records coming from a direct query such as Thing.find(params[:id]) return something slightly different :
#<Thing id: 1, ....>
Why does the first one doesn't allow me to query the objects with simple queries such as Thing.id as the second works perfectly fine?