You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not clear to me from the documentation and just trying to re-open the class is proving difficult because of its "special" inheriting scheme (I assume).
I'm needing to add specific belongs_to relationships per trackable type to be able to do some deep joins. I'm using this "hack" to do joins on polymorphic relationships which works pretty well.
So from what I see in the wiki here, I assume your recommendation would be to create an app/models/activity.rb file and do something like:
PublicActivity::Activity.class_evaldo# These are hacks to be able to use `joins` on the `trackable` polymorphic association.# Based on: http://stackoverflow.com/a/16124295belongs_to:post,->{where(activities: {trackable_type: "Post"})},foreign_key: "trackable_id"belongs_to:comment,->{where(activities: {trackable_type: "Comment"})},foreign_key: "trackable_id"belongs_to:project,->{where(activities: {trackable_type: "Project"})},foreign_key: "trackable_id"scope:by,->(user){where(owner: user)}defself.most_recentorder(:updated_at).lastendend
Can you confirm this is the best/expected way to do it or can you suggest a more "official" way?
The text was updated successfully, but these errors were encountered:
But, @oboxodo , stuff like that for me only works when putting the code into config/initializers/public_activity.rb. Does it truly work with a model file for you?
It's not clear to me from the documentation and just trying to re-open the class is proving difficult because of its "special" inheriting scheme (I assume).
I'm needing to add specific
belongs_to
relationships per trackable type to be able to do some deep joins. I'm using this "hack" to do joins on polymorphic relationships which works pretty well.So from what I see in the wiki here, I assume your recommendation would be to create an
app/models/activity.rb
file and do something like:Can you confirm this is the best/expected way to do it or can you suggest a more "official" way?
The text was updated successfully, but these errors were encountered: