# Problem with switching to join table

**URL:** <https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905>\
**Category:** Rails\
**Created:** [May 28, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905 "2008-05-28T21:11:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 28, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/1 "2008-05-28T21:11:54Z")

</div>

So I have classes:

```auto
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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 28, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/2 "2008-05-28T21:43:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 28, 2008, 10:11pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/3 "2008-05-28T22:11:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 29, 2008, 10:48am UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/4 "2008-05-29T10:48:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 28, 2008, 10:35pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/5 "2008-05-28T22:35:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 29, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/6 "2008-05-29T14:42:22Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 29, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/7 "2008-05-29T15:43:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 29, 2008, 3:54pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/8 "2008-05-29T15:54:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [May 29, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/problem-with-switching-to-join-table/138905/9 "2008-05-29T16:27:43Z")

</div>

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
