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
Class not recognized as MTI class #4
Comments
Hey @manuelmeurer, Thanks for reporting this! What version of Lastly, could you fork the project and write a failing test case? I'm happy to take a look if you could help out by doing that :) (Hint: I'm guessing it has to do with the use of |
So I took a stab at it (6edcb2b). I changed the |
My first idea was also that it has something to do with |
@manuelmeurer Thanks for doing that! Hmm, PostgreSQL Have you got other |
@voltechs I noticed that in the test app setup, the table name for the |
Oh wow. Great find! That was an attempt to make sure setting a table_name explicitly still worked (that I didn't botch that functionality). Looks like I need do have another class to isolate that behavior. I'll get to that right now :) |
Alright @manuelmeurer @yuki24, I've refactored how Even still, the refactor will degrade more gracefully and you should see your desired behavior without having to do anything further. I've updated the README to describe the behavior in more detail. If you wouldn't mind pointing to |
Thanks, I'll try it! |
Happy holidays, @manuelmeurer @voltechs! I'm also not sure about the naming conventions either. I was also concerned about the amount of the monkey-patches so I started my own work: develop...yuki24:overhaul. There is a number of improvements I have made in there:
@voltechs When you have time, could you check out my code here? Happy to help make the code safer and more stable. @manuelmeurer You could also try using my branch if you wouldn't mind: gem 'active_record-mti', git: 'https://github.com/yuki24/active_record-mti.git', ref: 'overhaul' |
@yuki24 Happy (belated) Holidays to you too! Thanks for that overhaul. It's definitely intriguing. I see a lot of cool solutions in there. I'm still picking through the changeset, I'll let you know when I'm finished. As it stands, I could definitely see incorporating some of the changes, some things I'm not entirely on board with or I don't understand yet. I have a mental block about dropping support for Rails 4.1 and Ruby 2.1, but I might come around :P |
Hi @yuki24, thanks for your work on this! |
Hi @yuki24, I tried your branch but have run into the problem that the child model doesn't recognize it's own fields, i.e. in the example I posted in the first message of this issue, if I do @voltechs Have you had the chance to look at @yuki24`s change in more detail? Regarding dropping support for Ruby <= 2.1 and Rails <= 4.1, I'm all for it since both are not supported anymore: |
I've been away from open source since New Year's holidays but will come back in the first week March. Thanks for bearing with me! |
Sure thing, enjoy your open-source holidays! 😎 |
@manuelmeurer Sorry for the delay, I finally had time to look into this. First of all, I ended up not using Postgresql's MTI in my app because of a number of reasons. With regards to your issue, a quick fix would be to add There is also a number of issues that I noticed in this gem:
So my conclusion is that you would have to give up on something to make it work. And even if you could get everything right in Ruby, the restrictions Postgresql's table inheritance brings in would not go away (I saw a helpful StackOver answer but I can't find it - will post it here once I do). I probably won't make any more changes to my branch. I'm sorry for dropping the ball, but it's hard to maintain things I don't use myself. But please do let me know if you have questions about Ruby or Rails. |
Hi @yuki24, Thanks for your detailed answer! Cheers, |
Hey all, I got around to merging in a bunch of the work @yuki24 did. It's much less polluty (it's a word now :P). It's not quite ready for primetime, but it's a huge step forward. Latest is in Thanks for your support guys :) |
Hey @manuelmeurer, here are my thoughts on @yuki24's concerns!
|
@voltechs Thanks!
If you think so, please do continue to maintain the project! It's just my concern and that shouldn't stop you from what you are doing. And I'm always here as part of the community for help if there's anything I could do for the project.
There is one case that is a bit tricky to cover. Let's say there is # app/models/user.rb
class User < AppliactionRecord; end
# app/models/admin_user.rb
class Admin < User
self.table_name = 'admin_users'
end
$ rails c
Rails.env # => 'development'
defined?(AdminUser) # => nil
User.all # => fails to look up the AdminUser constant
AdminUser # => forces Rails to load AdminUser
User.all # => works as expected This edge case is easy to miss if the test suite in the gem is eager-loading the dummy Rails app in the test. STI doesn't have this issue as the class name is simply stored in the database and AR just calls the |
Hey @yuki24,
I certainly will! I love this project and we use it in production at work, so I can vouch for its stability and utility. I’m a huge fan of PostgreSQL’s true inheritance feature. Regarding the I’ll be making another pre-release here shortly and I’m working on getting it rolled out to our production environment. I’ll release a full (minor) version rev in concert with that. |
Unfortunately my
AdminUser
class is not recognized as a MTI class. :(I'm running Rails 4.2.10 and this is my setup:
When I check
AdminUser.mti_type_column
andAdminUser.tableoid_column
on the console, they are bothnil
, which they shouldn't be according to the specs.What can I do to further help debugging this problem?
The text was updated successfully, but these errors were encountered: