# Polymorphism messing with me

**URL:** <https://www.ruby-forum.com/t/polymorphism-messing-with-me/135262>\
**Category:** Rails\
**Created:** [April 20, 2008, 9:07am UTC](https://www.ruby-forum.com/t/polymorphism-messing-with-me/135262 "2008-04-20T09:07:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [April 20, 2008, 9:07am UTC](https://www.ruby-forum.com/t/polymorphism-messing-with-me/135262/1 "2008-04-20T09:07:57Z")

</div>

Maybe one of you guys can figure this out:

User

- has\_many :comments

Comment

- belongs\_to :user
- belongs\_to :commentable, :polymorphic =\> true

Story

- has\_many :comments, :as =\> commentable

I have a story (variable called story) and I say:  
story.comments.create :user\_id =\> current\_user.id

and now story.comments contains this comment but not user.comments.  
The comment that was created has a commentable\_id, a commentable\_type,  
but not a user\_id, even if I specify it explicitly like above.

Am I going about creating the comment wrong or did I setup the  
association wrong?

Thanks,  
JB

---

<div class="post-metadata">

**Author:** ![Jables](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/58956e/32.png) [@Jables](https://www.ruby-forum.com/u/Jables)\
**Post date:** [April 20, 2008, 2:43pm UTC](https://www.ruby-forum.com/t/polymorphism-messing-with-me/135262/2 "2008-04-20T14:43:19Z")

</div>

no your setup is right and so is the creating  
but in that case you may have to reload the User object after saving the  
new Comment. ActiveRecord objects even if very smart in some ways,  
mainly reflect the state of the db at the point of their creation (eg  
User.find)  
Rails updates Story immediately, but does not check for all other  
possibly involved models or checks if there are any objects of them in  
memory at this time.
