# Association and validation

**URL:** <https://www.ruby-forum.com/t/association-and-validation/164990>\
**Category:** Rails\
**Created:** [April 8, 2009, 3:03am UTC](https://www.ruby-forum.com/t/association-and-validation/164990 "2009-04-08T03:03:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tiago\_Z.C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@Tiago\_Z.C](https://www.ruby-forum.com/u/Tiago_Z.C)\
**Post date:** [April 8, 2009, 3:03am UTC](https://www.ruby-forum.com/t/association-and-validation/164990/1 "2009-04-08T03:03:56Z")

</div>

Hi  
I’m having some issues with models that i don’t know which is the best  
way  
of doing that.

I have Post model…

class Post \< ActiveRecord::Base

validates\_presence\_of :name, :title

has\_many :comments

end

and the Comment model.

class Comment \< ActiveRecord::Base

validates\_presence\_of(:post)

belongs\_to :post

end

If I open the console, and start write some lines:

c = Comment.new

p = post.new

c.post = p

c.save

I receive the true feedback but, what about the presence of name and  
title  
on post???

Thank you…

–  
Tiago ZortÃ©a de Conto  
Mac User - MAC OS X Leopard  
MSN: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Tiago\_Z.C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5fc32e/32.png) [@Tiago\_Z.C](https://www.ruby-forum.com/u/Tiago_Z.C)\
**Post date:** [April 8, 2009, 3:48am UTC](https://www.ruby-forum.com/t/association-and-validation/164990/2 "2009-04-08T03:48:31Z")

</div>

i’m sorry, forget my question, i found the awnser.

class Comment \< ActiveRecord::Base

validates\_presence\_of(:post)

belongs\_to :post, :validate =\> true

end

🙂

On Tue, Apr 7, 2009 at 10:03 PM, Tiago Z.C [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> has\_many :comments
> 
> –  
> Tiago ZortÃ©a de Conto  
> Mac User - MAC OS X Leopard  
> MSN: removed\_email\_address@domain.invalid

–  
Tiago ZortÃ©a de Conto  
Mac User - MAC OS X Leopard  
MSN: removed\_email\_address@domain.invalid
