-
Notifications
You must be signed in to change notification settings - Fork 903
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
Postgres JSON data type #287
Comments
@daxter - Do you know if there is some documentation available for the HStore support that Rails 4 offers? I agree that it makes sense to offer this functionality, but I think the solution is not as easy as you suggest. It will need to detect whether the database being used by |
Postgres offers both HStore and JSON data types. HStore is a key-value store for strings, while the JSON data type is fully qualified JSON with numbers, arrays, and nested objects. There's no need to check for PostgreSQL itself. If Rails is reporting the data type of the column as |
Ok, then I think it makes sense to just offer support for inserting into columns of type |
It'd probably be best not to try supporting HStore. For example, let's say I have a model that has Postgres Array for one column, and I try using paper_trail with that model. How would HStore handle that? In comparison, the JSON data type supports arrays. |
@daxter - What is the expected behavior when we are inserting an attribute into the Also, agreed about |
There shouldn't be any need to serialize it, because Rails will do so automatically.
I haven't delved too far into the paper_trail code; where exactly is this happening?
That's exactly my point; HStore probably shouldn't be supported, instead we should focus on the JSON data type. |
@daxter - So I think I've come up with a successful implementation. The only issue seems to be that |
No, I'm not sure how to fix that. Could you create a PR so I could see your changes and try them out? |
Just pushed a branch, json_column_support. Try it out and let me know what you think. |
Cool, thanks. Looking at it, maybe it would be better to create a proxy serializer like I did above. The benefit is that there's less imbedded knowledge interspersed in the code. Instead, it just uses whichever serializer is available. |
Actually probably a good idea. That being said, the implementation works as you expected, right? |
I haven't actually tried using paper_trail that much thus far. That comes tonight :) |
@daxter - Cleaned up the code on the |
PostgreSQL has a built-in JSON data type, and Rails 4 has native support for it.
Right now I'm using this hack:
It seems like it could be fairly simple to integrate support into paper_trail
The text was updated successfully, but these errors were encountered: