# Multiple belong\_to associations & build

**URL:** <https://www.ruby-forum.com/t/multiple-belong-to-associations-build/150040>\
**Category:** Rails\
**Created:** [October 2, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/multiple-belong-to-associations-build/150040 "2008-10-02T19:51:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonas\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jonas\_s](https://www.ruby-forum.com/u/jonas_s)\
**Post date:** [October 2, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/multiple-belong-to-associations-build/150040/1 "2008-10-02T19:51:31Z")

</div>

Hey guys,

I have a Comment model which belongs\_to a Post and a User model.  
Now I want to be able to build a comment for this User and this Post.  
Does it really have to go like this:

@comment = @idea.comments.build  
@comment.user = current\_user

Is there a better way to do this?

Thanks,  
Jonas

---

<div class="post-metadata">

**Author:** ![jonas\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dfb087/32.png) [@jonas\_s](https://www.ruby-forum.com/u/jonas_s)\
**Post date:** [October 2, 2008, 8:10pm UTC](https://www.ruby-forum.com/t/multiple-belong-to-associations-build/150040/2 "2008-10-02T20:10:20Z")

</div>

On 2 Oct 2008, at 18:50, Jonas S. wrote:

> Hey guys,
> 
> I have a Comment model which belongs\_to a Post and a User model.  
> Now I want to be able to build a comment for this User and this Post.  
> Does it really have to go like this:
> 
> @comment = @idea.comments.build  
> @comment.user = current\_user

well you can do @idea.comments.build :user =\> current\_user

but that’s about it as far as I know (and barring dirty tricks with  
with\_scope)

Fred
