The Ruby on Rails way for Model naming

Following the comment from Graeme Mathieson on my last post on Rails-CMDB about the the Rails way for naming of columns within Models. I’m planning on doing the following column rename for the next release of Rails-CMDB:

rename_column :assets, :delivery_date, :delivered_on
rename_column :assets, :removal_date, :removed_on

rename_column :locations, :start_date, :started_on
rename_column :locations, :end_date, :ended_on

rename_column :purchase_orders, :order_date, :ordered_on

rename_column :vendors, :last_order_date, :stopped_ordering_on

So the question for the Rails coders out there – does this seem correct ? There’s also a single table who’s primary field is not called name, so I guess to do it in the Rails way it should be changed as well.

I’ve also created about 90 unit test stubs and now just comes the hard part of coding the tests πŸ˜‰

Advertisements

2 thoughts on “The Ruby on Rails way for Model naming

  1. If it’s just the date (ie day resolution) that’s important then this looks fine. If you’d like the time as well, use eg delivered_at.

    By primary field do you meant the primary key? If so, it should always be an auto-incrementing integer ID.

    Write your tests first or I’ll have to beat you πŸ˜‰

  2. Craig:

    Yes, they are just date fields.

    I did not mean the primary key, I was meaning the main context for the data in a table row. In other tables (e.g. purchase_orders, the PO number is stored in the name column). I was thinking that in the hardware table, the field serial_number should be name instead.

    As for test, yes I have learned my lesson. Needing to add 90 unit tests, before moving onto functional tests was a mistake. This refactoring will be painful to complete.

    I’ll also need to add functional tests for all of the controllers as well. But I’ll fall in that pit when I come to it (i.e. after the unit tests).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s