Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex types diffs #33

Closed
palkan opened this issue Apr 7, 2017 · 1 comment
Closed

Complex types diffs #33

palkan opened this issue Apr 7, 2017 · 1 comment

Comments

@palkan
Copy link
Owner

palkan commented Apr 7, 2017

Related to #30

The problem

The log doesn't respect complex data types such as jsonb, array, hstore, etc (due to the usage of hstore under the hood. The values for these types are just strings.

We have to manually cast them back to appropriate Ruby structure.

Example:

post = Post.create!(tags: ['some', 'tag']) # tags is an array column

post.udpate!(tags: ['other'])

post.reload.diff_from(...)
#=> {"old"=>{"tags"=>["some", "tag"]}, "new"=>"{\"tags\": [\"other\"]}"}

# but should be

#=> {"old"=>{"tags"=>["some", "tag"]}, "new"=>{"tags"=>["other"]}}

The problem also may affect the at methods.

@jcsrb
Copy link
Contributor

jcsrb commented Apr 18, 2017

the information can be found inside the model like this

Post.column_for_attribute('tags').type

and based on that additional casting can be added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants