# ActiveRecord Validations (noob question)

**URL:** <https://www.ruby-forum.com/t/activerecord-validations-noob-question/108855>\
**Category:** Rails\
**Created:** [July 8, 2007, 4:49am UTC](https://www.ruby-forum.com/t/activerecord-validations-noob-question/108855 "2007-07-08T04:49:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cliffking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@cliffking](https://www.ruby-forum.com/u/cliffking)\
**Post date:** [July 8, 2007, 4:49am UTC](https://www.ruby-forum.com/t/activerecord-validations-noob-question/108855/1 "2007-07-08T04:49:55Z")

</div>

Hey everyone, I’m just beginning rails (and this list) and I am  
having a little trouble with something. I’m trying to make sure I  
validate everything that needs to be validated, but I’m having a hard  
time grasping how ActiveRecord handles validations. I have a schema  
like this:

Account

- has\_many Users
- has\_one ServicePlan

I’ve included my code sample at the bottom of the email. Basically I  
can do a ‘validates\_presence\_of :service\_plan’ but I can’t figure out  
how to ‘validates\_numericality\_of :service\_plan’ or  
‘validates\_numericality\_of :service\_plan\_id’ or anything. I BELIEVE  
I understand that I should never have to access  
Account.service\_plan\_id directly since I would always use  
Account.service\_plan.id, so is it correct that I dont have to  
validate the type of the service plan Id? I just “trust” rails?

Also, as a side question, how does rails translate class names into  
property names? I don’t quite grasp the naming convention. Is the  
above correct in that the ServicePlan belonging to an Account object  
is ‘MyAccount.service\_plan’ and not ‘MyAccount.servicePlan’?

Sorry for the beginner questions. I guess I gotta start somewhere  
right?

# Code Sample:

class Account \< ActiveRecord::Base  
has\_many :users  
has\_one :service\_plan  
validates\_presence\_of :name, :service\_plan  
validates\_numericality\_of :service\_plan # ??? Does this need to  
be validated?  
end

Thanks,  
Cliff

---

<div class="post-metadata">

**Author:** ![cliffking](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a87d85/32.png) [@cliffking](https://www.ruby-forum.com/u/cliffking)\
**Post date:** [July 8, 2007, 5:28am UTC](https://www.ruby-forum.com/t/activerecord-validations-noob-question/108855/2 "2007-07-08T05:28:56Z")

</div>

On Jul 7, 9:48 pm, Cliff P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve included my code sample at the bottom of the email. Basically I  
> can do a ‘validates\_presence\_of :service\_plan’ but I can’t figure out  
> how to ‘validates\_numericality\_of :service\_plan’ or  
> ‘validates\_numericality\_of :service\_plan\_id’ or anything. I BELIEVE  
> I understand that I should never have to access  
> Account.service\_plan\_id directly since I would always use  
> Account.service\_plan.id, so is it correct that I dont have to  
> validate the type of the service plan Id? I just “trust” rails?

The ID column is always an auto-incementing integer, so you don’t have  
to validate it.

> Also, as a side question, how does rails translate class names into  
> property names? I don’t quite grasp the naming convention. Is the  
> above correct in that the ServicePlan belonging to an Account object  
> is ‘MyAccount.service\_plan’ and not ‘MyAccount.servicePlan’?

Right. Ruby convention is all lower case, with underscores between  
English words to make it more readable (as opposed to, say, Java,  
which capitalizes the first letter of words after the first word).

> Sorry for the beginner questions. I guess I gotta start somewhere  
> right?

Don’t apologize, that’s what this list is for!

Jeff

> **[Hey Daddio!](http://www.softiesonrails.com)**
>
> Home of Hey Daddio Software
