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

allow user to follow stories and discussions #73

Open
Tracked by #38
madhums opened this issue Jan 3, 2024 · 0 comments
Open
Tracked by #38

allow user to follow stories and discussions #73

madhums opened this issue Jan 3, 2024 · 0 comments

Comments

@madhums
Copy link
Member

madhums commented Jan 3, 2024

Following #38, we'd want a user to follow stories and discussions.

  • When a user follows a story, he gets notified of any new story updates and discussions.
  • When a user follows a discussion, he gets notified of posts.

We can add a polymorphic association like so:

# app/models/user_subscription.rb
class UserSubscription < ApplicationRecord
  belongs_to :user
  belongs_to :subscribable, polymorphic: true
end

# app/models/user.rb
class User < ApplicationRecord
  has_many :user_subscriptions
end

# app/models/story.rb
class Story < ApplicationRecord
  has_many :discussions
  has_many :user_subscriptions, as: :subscribable
end

# app/models/discussion.rb
class Discussion < ApplicationRecord
  belongs_to :story
  has_many :posts
  has_many :user_subscriptions, as: :subscribable
end
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

No branches or pull requests

1 participant