# How to tackle this problem: habtm, :though, :as?

**URL:** <https://www.ruby-forum.com/t/how-to-tackle-this-problem-habtm-though-as/70490>\
**Category:** Rails\
**Created:** [September 29, 2006, 5:35pm UTC](https://www.ruby-forum.com/t/how-to-tackle-this-problem-habtm-though-as/70490 "2006-09-29T17:35:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bartz](https://www.ruby-forum.com/u/bartz)\
**Post date:** [September 29, 2006, 5:35pm UTC](https://www.ruby-forum.com/t/how-to-tackle-this-problem-habtm-though-as/70490/1 "2006-09-29T17:35:53Z")

</div>

Hello peeps,

I currently have the following models:  
Users, which can have multiple blog posts, and a Forum with topics and  
posts.  
So a user can post a blog item, but also a topic/post on the forum

I want to give my users the ability to “watch” a blog post, or a forum  
topic, so a little email will be sent when something happens on whatever  
they’re watching.

I can’t get my head around a good solution to tackle this problem. I  
want to have the possibily to extend my ‘watching’, because in the  
future my users want to watch something else, so I was thinking along  
the line of :polymorphic, but I can’t get it to work. Any ideas?..

---

<div class="post-metadata">

**Author:** ![bartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bartz](https://www.ruby-forum.com/u/bartz)\
**Post date:** [September 29, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/how-to-tackle-this-problem-habtm-though-as/70490/2 "2006-09-29T18:45:14Z")

</div>

On 9/29/06, Bart Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> topic, so a little email will be sent when something happens on whatever  
> they’re watching.
> 
> I can’t get my head around a good solution to tackle this problem. I  
> want to have the possibily to extend my ‘watching’, because in the  
> future my users want to watch something else, so I was thinking along  
> the line of :polymorphic, but I can’t get it to work. Any ideas?..

I think you’re on the right track with :polymorphic. However, some  
sample  
code would help in diagnosing your problem.

–

> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

Michael G.

---

<div class="post-metadata">

**Author:** ![bartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bartz](https://www.ruby-forum.com/u/bartz)\
**Post date:** [September 29, 2006, 6:56pm UTC](https://www.ruby-forum.com/t/how-to-tackle-this-problem-habtm-though-as/70490/3 "2006-09-29T18:56:27Z")

</div>

Michael G. wrote:

> On 9/29/06, Bart Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > topic, so a little email will be sent when something happens on whatever  
> > they’re watching.
> > 
> > I can’t get my head around a good solution to tackle this problem. I  
> > want to have the possibily to extend my ‘watching’, because in the  
> > future my users want to watch something else, so I was thinking along  
> > the line of :polymorphic, but I can’t get it to work. Any ideas?..
> 
> I think you’re on the right track with :polymorphic. However, some  
> sample  
> code would help in diagnosing your problem.

Well, I don’t really have any sample code to share, since I am in the  
process of trying to set it up. Except for maybe:

class User  
has\_many :blogposts  
has\_many :topics  
has\_many :forumposts  
end

class Post  
belongs\_to :user  
end

class Blogpost \< Post  
end

class ForumPost \< Post  
end

---

<div class="post-metadata">

**Author:** ![bartz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bartz](https://www.ruby-forum.com/u/bartz)\
**Post date:** [September 30, 2006, 2:06am UTC](https://www.ruby-forum.com/t/how-to-tackle-this-problem-habtm-though-as/70490/4 "2006-09-30T02:06:50Z")

</div>

On 9/29/06, Bart Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > future my users want to watch something else, so I was thinking along  
> > > the line of :polymorphic, but I can’t get it to work. Any ideas?..
> > 
> > I think you’re on the right track with :polymorphic. However, some  
> > sample  
> > code would help in diagnosing your problem.
> 
> Well, I don’t really have any sample code to share, since I am in the  
> process of trying to set it up. Except for maybe:

Well you mentioned in your earlier post that you tried :polymorphic and  
it  
did not work. I was trying to determine “what did not work” with  
:polymorphic.

class User

> end
> 
> class ForumPost \< Post  
> end

Check out:  
[http://blog.hasmanythrough.com/articles/2006/04/03/polymorphic-through](http://blog.hasmanythrough.com/articles/2006/04/03/polymorphic-through)

This is the most comprehensive tutorial I have seen or used for  
polymorphic  
associations.

–
