Skip to content

jsonb properties are included in the returned AR models even though they are not selected #190

@breis-sa

Description

@breis-sa

Hello! I'm using the latest version of the gem (1.4.0) and noticed a slightly odd behavior:

Say I have the following table

# config/schema.rb

create_table "examples", force: :cascade do |t|
  t.string "name"
  t.jsonb "configuration"
end

and model

# app/models/product.rb

class Example< ApplicationRecord
  jsonb_accessor :configuration,
                   foo: [:boolean, { default: false }],
                   bar: [:boolean, { default: false }],
                   baz: [:boolean, { default: false }]
end

if then I do

Example.select("id, name").first.attributes

I get

=> {"id"=>1, "name"=>"Example One", "foo"=>false, "bar"=>false, "baz"=>false}

Even though I did not include the configuration column or any of its properties in the select clause. Is that expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions