Skip to content

Does not dump JSON correctly with Polymorphic Embed #64

@joshuataylor

Description

@joshuataylor

I've seen this - #41

Seems that using the dumper dumps to string that can't be later read properly with SQLite, it stores it like this in a JSON field in SQLite:

"{\"property_type\":\"foo\",\"__type__\":\"something\"}"

instead of like this:

{"property_type": "foo", "__type__": "something"}

Means functions like json_extract etc won't work natively in SQLite.

I believe it's because when dumping it's done this way:

dumper.(:map, map)

So with SQLite, this dumps as a string:

{:ok,
 "{\"foo\":\"x\",\"bar\":\"2021-12-03T07:22:16.086910Z\",\"baz\":\"xxx\",\"__type__\":\"something\"}"}

But with Postgres it dumps as a map:

{:ok,
 %{
   :something => "hello",
   "__type__" => :"Whatever"
 }}

Not sure if this is an ecto_sqlite3 problem or a polymorphic_embed issue.

It looks like creating normal maps works properly as JSON.

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