views:

13

answers:

0

hi All,

Preface:

If you hang out in #rubyonrails on freenode this may sound like an echo to you as i asked it in there 2 days ago. After spending a number of hours researching AR associations, following my discussions in #rubyonrails, i still feel lost so I'm asking here. :)

Goal

I host a number of blogs. My intent is to create batch submissions where i take a Post, select the blogs I'd like the Post to be Submitted to, then give the Batch a submission date. Later on I'd like to create a Worker that queries the Batches and then actually submits the Post to it's associated Blogs.

The Confusion

I am confused about how I should setup my associations and the corresponding tables.

Here is what i have for Models.

class Blog < ActiveRecord::Base
  has_many :submissions
  has_many :posts, :through => :submissions
end


class Post < ActiveRecord::Base
  has_many :submissions
  has_many :blogs, :through => :submissions
end


class Submission < ActiveRecord::Base
  belongs_to :post
  belongs_to :blog
end

Here is what i have for Tables.

[Blogs]
id         :integer         not null, primary key
title      :string(255)
etc

[Posts]
id         :integer         not null, primary key 
subject    :string(255)
content    :text
etc

[Submissions]
id          :integer         not null, primary key
submit_date :datetime
post_id     :integer
forum_id    :integer
etc

Questions

  • I currently have no Batch model -- should i have this? Or can a "batch" be inferred by backtracing submissions?
  • If i should have a Batches model, would that mean the Submisson model then gets an additional foreign key?
  • Is there a more "rails way" to do this?
  • Any other input is welcome!

Thanks a lot for reading this gigantic post.