-
Notifications
You must be signed in to change notification settings - Fork 899
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
Reify on associations fails if using Single Table Inheritance #594
Comments
Sounds like you're onto something. Thanks for the bug report.
Any luck? Even a failing test would be welcome, thanks. |
Still working on this, Kevin? Were you able to write a failing test? Thanks. |
Hey, sorry. |
I recently adapted the AR bug report template for use in PaperTrail. Maybe it will help you write your failing test? Please check it out: https://github.com/airblade/paper_trail/blob/master/doc/bug_report_template.rb I hope it helps! |
Kevin, I think I've reproduced your issue: https://gist.github.com/jaredbeck/4664e45abe3aa09416ae Does that look like the issue you're seeing? |
I worked with Kevin on this, your gist does reproduce the issue. Here's another one too: https://gist.github.com/daneshd/f0e61744075e1617dbcb I was working on a fix for this issue but I haven't had the time to finish it. One thing I noticed in your report is you'd like the
Saving I tried to change the way the lookup was done to grab all the versions whose class is the base model here. I only started on the - where("#{version_table_name}.item_type = ?", assoc.class_name).
+ where("#{version_table_name}.item_type = ?", assoc.klass.base_class.name). This isn't enough though. You could have more than 1 record saved with the base class if your model uses other I tried iterating through the found versions to lookup and filter these by their Our implementation for versioning things caused some other issues for me so I had to put this fix on hold to figure that out. I never got around to |
This just came up again recently. What do you think about ecd1df7 as a recommendation? |
The STI related documentation from ecd1df7 looks good to me. Reifying the polymorphic associations are currently bugging out though. I think it may be better to say that it's a known issue instead. What do you think? |
https://github.com/airblade/paper_trail#5a-single-table-inheritance-sti now mentions this issue (#594) as a known issue. |
[Related to paper-trail-gem#594] [ci skip]
[Related to paper-trail-gem#594] [ci skip]
Danesh, have you done any more work on this since January? Is it still an issue with the latest version (currently 5.1.1)? Thanks. |
It´s still an issue with the latest version (8.1.1). |
Adding a
and
Here is an example with the required It seems that no changes to PT are necessary. Please try adding the |
My tests were done with I implemented a fix for this issue by adding a |
Thanks for the clarification, Andre, I'll check out your gist later.
Hmmm. I would like to fix this issue without adding a new column, if at all possible. I would almost rather drop support for STI than change our schema. |
@jaredbeck I would like to fix this without adding a new column, too.
|
Yeah, I thought about that, but I think it's ActiveRecord who sets the |
@jaredbeck I realize this is a very, very late response but no, sorry I never circled back to revisit this. |
I don't think you can get around saving The only solution that came to mind back when I was working on it was to use the base type for the lookup, let all the results load, and then filter through them until it found the correct one which matched the current record's |
@daneshd that is the only solution without adding a |
@jaredbeck I need this feature working for versioning my models correctly as soon as possible. I found that changing the class name on reification to the base class name fixes my issue. I changed that and opened an PR. This will not fix the reification issues mentioned by @daneshd on having multiple |
Thanks to André's work in #1028 this issue is partially fixed and released as 8.1.2. Also thanks to André, we have a failing (skipped) test in |
Closed by 06a5e30 (will release in 9.0.0) which improves the message of the error raised. Because it's a very rare issue on an experimental feature, I don't intended to work on it further (thus, closing this) but PRs are welcome. |
See the changes to the changelog and readme for details.
…se STI (paper-trail-gem#1108) See the changes to the changelog and readme for details.
It appears as though if Single Table Inheritance is being used on an association, if you try to reify with has_many: true or has_one: true, it will not find and build the previous version of the association and instead always use the current version of the association when browsing previous versions.
I believe this is happening because if STI is used, the item_type is always stored as the base class. But when calling the method reify_has_many_directly, it is using the main class of the association. This builds a WHERE clause that is looking for the wrong value in the item_type column.
ex:
The last line there will produce a SQL query like this:
But item_type will never be 'Authorship', it is always stored as Assignment. I'm still working on figuring out a solution to this if I can, but this seems to be what is happening from my understanding.
Modifying the database manually and changing the item_type column from Assignment to Authorship results in being able to view the correct versions of the association as I browse through the document history.
The text was updated successfully, but these errors were encountered: