Skip to content

How can we initialize the activerecord object with jsonb attributes based on the json structure? #61

@flyingboy007

Description

@flyingboy007

I have a user model with address field as jsonb column.

class User < ApplicationRecord
#name :string, age :integer, address :jsonb

  include SchemaStructures
  validates :address, allow_blank: true, json: { message: lambda { |errors|
    errors
  }, schema: JSON_SCHEMA_ADDRESS }


end

Now if I initialize the object it will show the jsonb attribute as nil

User.new()
{name: nil, age: nil, address: nil}

But is it possible to generate the address structure from existing json_schema. so it will show like a normal object but nested like below

{name: nil, age: nil, address: {'city': nil, postcode: nil}}

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions