Skip to content
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

Support Polymorphic Associated Objects: Take 2 #29

Closed
wants to merge 4 commits into from

Conversation

kaspth
Copy link
Owner

@kaspth kaspth commented Dec 10, 2024

In #25, we discussed how to have Polymorphic Associated Objects and we ultimately ruled that it was better to share code via concerns.

I tried a slightly alternate approach, but I'm still coming to the same conclusion: trying to remove/defer the connection to an Active Record class opens up a whole bunch of complexity. E.g. extension blocks needs to be captured and then applied when the actual connection happens.

So I'm opening this just for reference and I'm closing it immediately in favor of writing up the concerns approach.

kaspth and others added 4 commits June 2, 2024 13:15
Sometimes there's certain behavior you'd like to share between multiple objects.
However, Associated Object's design was purposefully written to only support associating with
one distinct class.

This tries to shimmy that open a bit more, so you can do:

```ruby
class Pricing < ActiveRecord::AssociatedObject::Polymorphic
end

class Post::Pricing < Pricing
end

class Comment::Pricing < Pricing
end
```
@kaspth kaspth self-assigned this Dec 10, 2024
@kaspth
Copy link
Owner Author

kaspth commented Dec 10, 2024

Still thinking of trying to have something like this:

class Pricing < ActiveRecord::AssociatedObject::Polymorphic
end

class Post::Pricing < Pricing
end

Where Polymorphic would be a slimmed down interface. Really it'd just be an empty module because we only want to share instance methods, but the whole thing feels pretty clunky.

Seems like the concern for sharing code is the easier approach still.

@kaspth kaspth closed this Dec 10, 2024
@kaspth kaspth deleted the polymorphic-associated-objects branch December 10, 2024 14:54
kaspth added a commit that referenced this pull request Dec 10, 2024
Feels a bit iffy, but it's easier for us to support versus trying to bake in "polymorphic" support via inheritance.

See #25 and #29 for the previous discussion.
kaspth added a commit that referenced this pull request Dec 10, 2024
…-modules

Feels a bit iffy, but it's easier for us to support versus trying to bake in "polymorphic" support via inheritance.

See #25 and #29 for the previous discussion.

So given the tradeoffs I think this is the best we've got.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant