I have a model Vehicle which actually maps to the at_vehicles table. So while running my test script for Vehicle, I get the error "'vehicles' relation does not exist". Is there a hack , that could allow me to run my tests with the current db schema as is? Thanks.
views:
23answers:
2
+1
A:
It's not a hack, but you can use set_table_name
in your model (assuming rails 2.3.x). The test is doing the right thing, telling you that your active record association is not setup correctly. You need to define the relationship in your model.
class Vehicle < ActiveRecord::Base
set_table_name "at_vehicles"
end
Jed Schneider
2010-08-27 11:53:13
I did that, but it now says relation obus does not exist. i have another model named Obu which maps to at_vehicle_device and I updated the Obu model to set_table_name "at_vehicle_device". Any clue? P.S : I'm helpless but to stray away from the Rails convention since my app talks to the client's db.
Shreyas Satish
2010-08-27 14:35:50
im not sure of the relationship characteristics for your problem in the comment, you say _obus_ doesn't exist, but you are describing an _Obu_ model? Rails provides you with the necessary tools to manage poor convention with convention so you can be happy.
Jed Schneider
2010-08-27 14:46:15
Postgres describes a table as a relation.Its trying to map to the 'obus' table where-in it should actually be mapping to at_vehicle_device . Anyway thanks Jed !
Shreyas Satish
2010-08-27 15:20:10
actually it is rails that is trying to define the obus table, the plural form of 'obu'. the set_table_name should work too but you may also need to `set_primary_key`
Jed Schneider
2010-08-27 16:50:52
A:
The problem was with the Fixtures. The fixture file 'obus' was trying to reach the obus table. So in case you're straying away from convention and using table names different from that of your models, You will also alter your fixture filenames
Shreyas Satish
2010-08-31 06:42:19