Skip to content

Default value for Hstore column #11520

@vgeorge

Description

@vgeorge

Is is possible to set a default value for the new native Hstore column?

I'll quote @jjb, who explains the problem at issue 22 of activerecord-postgres-hstore gem:

Here's a problem I have, which might be (very?) common for users of this gem: I have a model Foo with an hstore column metadata. It's possible that it has no metadata at all, or many key/values. Wherever I access the metadata, I have to do ye olde @foo.metadata && @foo.metadata['my_key'] because @foo.metadata might be nil.

I would rather that in the case of a NULL metadata column, @foo.metadata returned {}. In my use case, metadata being nil has no semantic purpose.

Seems like it was solved for the gem in this commit.

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