-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
ActiveRecord Inheritance without STI? #5541
Comments
I find having multiple tables for an STI is not the right way. I think having the bypass option would overcomplicate the architect in which mixins should be used. |
I agree with you on multi table inheritance, STI is superior. However, I'm just interested in sharing functionality like the same connection to a different db across a collection of ActiveRecord models, how would u do that efficiently w mixins? On Mar 21, 2012, at 9:13 PM, Trung Lêreply@reply.github.com wrote:
|
@joegoggins I haven't bumped into such cases, so please excuse me if my solution turns out quite clumsy. I'd create a YAML file with structure like this:
then I write a module to lookup for the right connection given that class name constant is provided. |
I think that the following will do what you are looking for:
|
@markmcspadden thanks for the feedback, this fixes my problem. I've also added a commit to docrails that clarifies when to use this functionality: @joneslee85 thanks for the suggestion--I think @markmcspadden 's recommendation will work for this use case, but I'll comment on this issue, if I end up implementing some variant of your implementation idea. |
If you have:
and you do:
you get:
which means the:
statement isn't honored.
I'm not sure if this is intentional behavior or not. If it is intentional it would be nice if
self.table_name=
raised an exception instead of failing later, once you start to use the child classes.Alternatively, it would be even better if you could optionally bypass STI with something like:
I have several situations where I've really needed inheritance in ActiveRecord without STI (where mixins don't work very well), and the bit of googling around I've done seems to confirm there are others out there who would appreciate it too. If there is appetite on the Rails core team to make this happen, I would love to help out.
The text was updated successfully, but these errors were encountered: