-
Notifications
You must be signed in to change notification settings - Fork 239
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
Doesn't work with table_prefixes #21
Comments
I fixed it in my fork: https://github.com/juddblair/closure_tree Rspec is passing, and I built and tested the gem locally with my application, and everything looks good. I didn't write a breaking test for the implementation, but I can submit a pull request for my fix if you'd like. |
Excellent issue request, sir. Thanks for your thoroughness! I pulled your change onto a new branch, but the weather's too nice to keep typing right now. I think we (and by "we", I don't mean you have to do it) should add a couple breaking tests (to test with a prefix and a suffix), or do something clever with running the whole test suite with Label or Tag with or without a prefix, just to make sure things are working in all environments. Thanks again for taking the time to write this up! |
Sure thing - I started playing around with the tests since, despite the nice weather, I'm under the weather. I added a prefix and suffix to the spec helper and noticed a few things:
Personally, I think the tests should run with all permutations (prefix, suffix, prefix+suffix, neither), but this seems like a good start. I updated my fork with my changes. |
All permutations: http://travis-ci.org/#!/mceachen/closure_tree/builds/2473467 We'll see how it goes. |
released 3.6.0. Thanks again for your help! |
Sweet! Thanks for the quick turnaround with the release, much appreciated. |
I'm using a table prefix, which is specified in application.rb like so:
config.active_record.table_name_prefix = "d2"
I have a model called "TagDefinition" that I have acts_as_tree on.
The problem is that acts_as_tree appears to look at the table name for TagDefinition, which due to the prefix is actually "d2_tag_definition", and then creates a model "D2TagDefinitionHierarchy" - ActiveRecord adds the table prefix to this, so it thinks the table name for this model is d2_d2_tag_definition_hierarchies. The actual table I added with the migration is d2_tag_definition_hierarchies.
So, the SQL queries in the gem where you manually insert the table name work fine, but if you do something like an ActiveRecord delete on TagDefinition (or pretty much anything where ActiveRecord tries to handle the generated Hierarchy object, rather than with manual SQL), it errors out when ActiveRecord uses the prefix and tries to select from d2_d2_tag_definition_hierarchies, which doesn't exist.
Rails had a similar bug in the table dumper, described here: rails/rails@1bdc098#activerecord/lib/active_record/schema_dumper.rb
I think if you change hierarchy_class_name to strip the prefix from the table name like rails did, you should be fine.
The text was updated successfully, but these errors were encountered: