Naming Conventions


#1

So, RoR is better at grammer than I. Well so is my nine year old.

If I have a table named “people_type” will Rails see this as singular
because of the _type or will it consider it the plural of “person_type”
?

Is there a link to Rails that lists what words it knows, or what words
not to use in table design etc.

Kindest regards.


#2

On Jan 2, 2006, at 12:06 PM, Andy P. wrote:

Kindest regards.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Andy-

Topfunky has put up an excellent tool for figuring out what rails

thinks the plural of a word is. You can find it here:

http://nubyonrails.com/tools/pluralize

Cheers-
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732


#3

Hi Andy,

On 1/2/06, Andy P. removed_email_address@domain.invalid wrote:

So, RoR is better at grammer than I. Well so is my nine year old.

If I have a table named “people_type” will Rails see this as singular
because of the _type or will it consider it the plural of “person_type”
?

Is there a link to Rails that lists what words it knows, or what words
not to use in table design etc.

You can use Ruby to find out how Rails’ naming conventions work:

| % script/console
| Loading development environment.

What table name should be used for the PersonType model?

| >> “PersonType”.tableize
| => “person_types”

What model does the table named “people_type” map to?

| >> “people_type”.classify
| => “PeopleType”

Does this match what Rails expects for the PeopleType model?

| >> “PeopleType”.tableize
| => “people_types”

No – if the model is called PeopleType, we need to use “people_types”
for the table name instead. You can make a method which automates this
check for you:

| >> class String
| >> def canonical_table_name?
| >> self == classify.tableize
| >> end
| >> end
| => nil
| >> “person_types”.canonical_table_name?
| => true
| >> “people_type”.canonical_table_name?
| => false


sam


#4

Which now leads me to…

If I have two tables

“people”

  • id
  • name

&

“person_types”

  • id
  • kind

Am I right in thinking that the row in “person” linking too
“person_types” should be ;

“people”

  • id
  • name
  • PersonType_id (as opposed to “person_types_id”)

Again, many thanks for your time.

Kindest reagrds.


#5

Sam, Ezra

Outstanding! thankyou both, great information.

Regards.


#6

On Jan 2, 2006, at 7:29 PM, Andy P. wrote:

“person_types”

  • id
  • kind

Am I right in thinking that the row in “person” linking too
“person_types” should be ;

“people”

  • id
  • name
  • PersonType_id (as opposed to “person_types_id”)

Stranger yet. :slight_smile:

person_type_id, because it only points to one type. :slight_smile:


– Tom M.


#7

Thanks Tom.

I think I need to watch The Life of Brian again. Remember the bit with
the Centurian, when Brian is writing graffiti on the palace wall? The
Centurion catches him in the act.

Centurion: What’s this, then? “Romanes eunt domus”? People called
Romanes, they go, the house?

Brian: It says, "Romans go home. "

Centurion: No it doesn’t ! What’s the latin for “Roman”? Come on, come
on !

Brian: Er, “Romanus” !

Centurion: Vocative plural of “Romanus” is?

and on it goes …


#8

:slight_smile:


– Tom M.


#9

Andy P. wrote:

If I have a table named “people_type” will Rails see this as singular
because of the _type or will it consider it the plural of “person_type”?

If your terminology is awkward to use, it may indicate a poor choice for
the term. Why don’t you consider a term that more naturally reflects the
concept, such as “role”, “officer_grade” or “job_description”? In a
journalism class I was told to avoid using the word “people” as it is
usually too generic, and I find that advice serves me well in model
terminology as well.

By the way, someone should let the Rails pluralizer know that the plural
of mother_in_law is mothers_in_law :slight_smile:


#10

For my first RoR test app I tried to use the table “books”.

The singular form I wanted was invoice, credit report, payment, etc.

Happily I realized the futulity of this before I even got started.

I still plan to do something real along the lines of the above. Maybe
“records”?

On 1/2/06, Andy P. removed_email_address@domain.invalid wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Greg F.
The Norcross Group
Forensics for the 21st Century


#11

joshua wrote:

If your terminology is awkward to use, it may indicate a poor choice for
the term. Why don’t you consider a term that more naturally reflects the
concept, such as “role”, “officer_grade” or “job_description”? In a
journalism class I was told to avoid using the word “people” as it is
usually too generic, and I find that advice serves me well in model
terminology as well.

Noted, and I agree, but…

A “person” may be or have a

 -- role
 --- officer_grade
 ---- job_description

I understand what you are saying and I like the way Rails makes you
really think “Naming” something rather seriously.


#12

That’s not related to naming conventions. That is related to how
scaffolding
works. Please make a new post for this if you require more help.


#13

Nika Ta wrote:

I’m having problem with naming conventions.
I’ve 2 tables (states and steps), states has id, name, message, and
step_id
but when I go to http://127.0.0.1:3000/state it only pulls up the first
3 columns.
If I change step_id to stepid, it will show up but I want to be able to
show db info with names with underscore. How can this be dones?

This is just a guess, but it may be that RoR is interpreting step_id as
a
reference (i.e., a foreign key) to the steps table. What do your
state_controller.rb index method and state/index.rhtml file look like?

hth,
Bill


#14

Hi Everyone,

I’m having problem with naming conventions.
I’ve 2 tables (states and steps), states has id, name, message, and
step_id
but when I go to http://127.0.0.1:3000/state it only pulls up the first
3 columns.
If I change step_id to stepid, it will show up but I want to be able to
show db info with names with underscore. How can this be dones?
Thanks,
Nika

random at tangaz dot net

Andy P. wrote:

Which now leads me to…

If I have two tables

“people”

  • id
  • name

&

“person_types”

  • id
  • kind

Am I right in thinking that the row in “person” linking too
“person_types” should be ;

“people”

  • id
  • name
  • PersonType_id (as opposed to “person_types_id”)

Again, many thanks for your time.

Kindest reagrds.