Problem with switching to join table

So I have classes:

class Calendar < ActiveRecord::Base
  has_many :stamps

class Stream < Calendar
  has_many :events, :through => :stamps

class Audience < Calendar
   has_many :events, :through => :stamps

class Stamp < ActiveRecord::Base
  belongs_to :user
  belongs_to :customevent
  belongs_to :event
  belongs_to :calendar

class Event < ActiveRecord::Base
  belongs_to :user
  has_many :stamps, :dependent => :delete_all
  has_many :streams, :through => :stamps, :source => :calendar,
:dependent => :destroy
  has_many :audiences, :through => :stamps, :source => :calendar,
:dependent => :destroy

Initially, Event and Audience were:

class Audience < Calendar
  has_and_belongs_to_many :events

class Event < ActiveRecord::Base
  belongs_to :user
  has_many :stamps, :dependent => :delete_all
  has_many :streams, :through => :stamps, :source => :calendar,
:dependent => :destroy
  has_many_and_belongs_to_many :audiences

This was so that an Audience calendar would be completely different from
a Stream calendar. Now I want them to be basically the same thing just
with a different categorization, so I did the above changes. The
problem is that now none of the events I make and put in an audience
calendar get saved to the audience calendar.

I think it’s an issue with there being too many connections (events -
audiences - stamps - streams) or something like that. Can somebody
please enlighten me about what’s happening and how i could possibly fix
it?

Thanks a lot!

On 28 May 2008, at 20:11, Amanda … wrote:

This was so that an Audience calendar would be completely different
from
a Stream calendar. Now I want them to be basically the same thing
just
with a different categorization, so I did the above changes. The
problem is that now none of the events I make and put in an audience
calendar get saved to the audience calendar.

What is it you’re doing that isn’t producing the expected result?

Fred

Frederick C. wrote:

On 28 May 2008, at 20:11, Amanda … wrote:

This was so that an Audience calendar would be completely different
from
a Stream calendar. Now I want them to be basically the same thing
just
with a different categorization, so I did the above changes. The
problem is that now none of the events I make and put in an audience
calendar get saved to the audience calendar.

What is it you’re doing that isn’t producing the expected result?

Fred

My site displays a list of all the calendars (audiences and streams) and
each has a link that shows how many events are in the given calendar.
This link should go to a page that lists all the events in the calendar.
Before changing the code, the audience calendars’ links displayed the
correct numbers and the events appeared as they should when I clicked
the link. Now for all the audiences, the link shows that there are 0
events in it. I think this could be because I’m no longer using the
“audiences_events” table I was using with has_and_belongs_to_many and
the events that were stored in there before aren’t getting switched over
to wherever they should be? lol I don’t really know what’s going on in
the database with these changes, I’ve only been using Ruby on Rails for
a couple weeks now.

On 28 May 2008, at 21:11, Amanda … wrote:

Before changing the code, the audience calendars’ links displayed the
correct numbers and the events appeared as they should when I clicked
the link. Now for all the audiences, the link shows that there are 0
events in it. I think this could be because I’m no longer using the
“audiences_events” table I was using with has_and_belongs_to_many and
the events that were stored in there before aren’t getting switched
over
to wherever they should be? lol I don’t really know what’s going on in
the database with these changes, I’ve only been using Ruby on Rails
for
a couple weeks now.

Well the contents of audiences_events is certainly not going to get
magically get migrated for you.

Fred

Should I be using has_many_polymorphs instead? There seems to be an
extra connection I’m trying to make than on any other many-to-many
example I’ve looked up.

Well the contents of audiences_events is certainly not going to get
magically get migrated for you.

Fred

Thats the problem…I don’t know how to do that

On 29 May 2008, at 13:42, Amanda … wrote:

Well the contents of audiences_events is certainly not going to get
magically get migrated for you.

Fred

Thats the problem…I don’t know how to do that

every row in the audiences_events table will become a row in the
stamps table by the looks of it.

Fred

Frederick C. wrote:

On 29 May 2008, at 13:42, Amanda … wrote:

every row in the audiences_events table will become a row in the
stamps table by the looks of it.

Fred

Would I have to do that manually? If so, it wouldn’t be hard to do in
the test database…but when we go to the production database there are
a ton of rows in audiences_events that would have to be switched over

On 29 May 2008, at 14:54, Amanda … wrote:

Would I have to do that manually? If so, it wouldn’t be hard to do in
the test database…but when we go to the production database there
are
a ton of rows in audiences_events that would have to be switched over

I suggest you write a script that does that (and test it on a copy of
the production database first!)

Fred