basic question, Can a user update post of another user ? If yes then your approach is correct.
If no, then you need not have user_id in alerts table in this case relationships will be class Post < ActiveRecord::Base belongs_to :creator, :class_name => "User", :foreign_key => "created_by" has_many :alerts, :dependent => :destroy end class User < ActiveRecord::Base has_many :created_posts, :class_name => "Post", :foreign_key => "created_by" has_many :alerts, through => :created_posts # Need not have , :dependent => :destroy end class Alert < ActiveRecord::Base belongs_to :post end -Sandip R~ On Fri, Jun 5, 2009 at 8:25 PM, JL Smith <autige...@gmail.com> wrote: > > I'm building a blog application that allows users to create and edit > blog posts. I want to add the ability for a user to check a box on > the post page that enables an alert on the post that sends an email to > the user when the post is updated. > > I would think my alerts table would simply consist of a user_id, a > post_id and a created_at timestamp. So in modeling the associations > for this, my first thought was that this would be a has_many :through > association but I'm not sure how or where I would make that > association. > > Is this thought process on the right path? Thanks for any help. > > class Post < ActiveRecord::Base > belongs_to :creator, :class_name => "User", :foreign_key => > "created_by" > has_many :alerts, :dependent => :destroy > end > > class User < ActiveRecord::Base > has_many :created_posts, :class_name => "Post", :foreign_key => > "created_by" > has_many :alerts, :dependent => :destroy > end > > class Alert < ActiveRecord::Base > belongs_to :post > belongs_to :user > end > > > -- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---