2

I have a simple ActiveRecord object representing an estimated time of arrival.

class Eta < ActiveRecord::Base
    belongs_to :stop
    belongs_to :vehicle
    validates :timestamp, :presence => true
end

In my database, I created the corresponding columns stop_id, vehicle_id, and timestamp (of type datetime).

I have a rake task set up to perform operations on this table, but it is generating SQL that doesn't make sense. If I try to run:

for eta in Eta.all
    puts eta.timestamp
end

It tries to SELECT * FROM eta, however the table is named etas, not eta.

The pluralized database naming is consistent with the rest of the tables created from ActiveRecord objects and I successfully created a similar ActiveRecord object that works correctly.

class PrecedingCoord < ActiveRecord::Base
    belongs_to :stop
    belongs_to :route
    belongs_to :coord
end

In the rake file:

for eta in PrecedingCoord.all
    puts eta.coord.latitude
end
1
  • hahahaha... this one makes me LOL... convention over configuration has occasional hiccups Commented Oct 31, 2011 at 15:40

1 Answer 1

6

Rails sets the plural of ETA as ETA.

> 'eta'.pluralize
=> "eta"

If you have already created a table called etas, you can set this in your model:

class Eta < ActiveRecord::Base
  set_table_name "etas"

  belongs_to :stop
  belongs_to :vehicle
  validates :timestamp, :presence => true
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.