Datamapper unable to find table

125 Views Asked by At

I have an app running on my Raspberry Pi with Postgresql 9.1.

My first iteration was to add weather records into a table called "Weathers". That was successful.

My next iteration is to use psychopg2 to write records from Python into a different table called "weather". That also is succcessful.

What should also be successful is to change the Weather class in my app to the new fields. But DataMapper returns a mapping error:

@records = Weather.all(:order => :timestamp.desc)
ArgumentError at /
+options [:order]+ entry :timestamp does not map to a property in Weather

Rereading the datamapper.org docs suggests it's something to do with my table name so I migrated over the older "weathers" table into another called "older" and dropped the "weathers" table. But DataMapper still fails to find this table.

My Postgres environment with a truncated view of the target table is:

            List of relations
 Schema |   Name    | Type  | Owner 
--------+-----------+-------+-------
 public | customers | table | pi
 public | older     | table | pi
 public | systemlog | table | pi
 public | weather   | table | pi
(4 rows)

                                                         Table "public.weather"
           Column            |            Type             |                      Modifiers                       | Storage  | Description 
-----------------------------+-----------------------------+------------------------------------------------------+----------+-------------
 id                          | integer                     | not null default nextval('weather_id_seq'::regclass) | plain    | 
 timestamp                   | timestamp without time zone | default now()                                        | plain    | 
 currentwindspeed            | real                        |                                                      | plain    | 
 bmp180temperature           | integer                     |                                                      | plain    | 
Indexes:
    "weather_pkey" PRIMARY KEY, btree (id)
Has OIDs: no

My Datamapper class is:

class Weather
  include DataMapper::Resource
  property :id,  Serial
  property :bmp180temperature, String
  property :insidehumidity, String
  property :totalrain, String
  property :currentwinddirection, String
  property :currentWindSpeed, String
  property :timestamp, DateTime
end
DataMapper.finalize
Weather.auto_upgrade!

Since this is Ruby I fired-up IRb, required the Datamapper gem and got:

records = Weather.all
DataObjects::SyntaxError: ERROR:  column "bmp180temperature" does not exist
LINE 1: SELECT "id", "bmp180temperature", "insidehumidity", "totalra...
                     ^
 (code: 50360452, sql state: 42703, query: SELECT "id", "bmp180temperature", "insidehumidity", "totalrain", "currentwinddirection", "current_wind_speed", "timestamp" FROM "weathers" ORDER BY "id", uri: postgres:pi@localhost/postgres?scheme=postgres&user=pi&password=pw&host=localhost&port=&path=/postgres&query=&fragment=&adapter=postgres)
        from /var/lib/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:147:in `execute_reader'
        from /var/lib/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:147:in `block in read'
        from /var/lib/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'

This makes me think it's not finding the right table. It seems to be OK with the id column, perhaps.

I see what appears to be DataMapper is being used for PHP in the CodeIgniter framework but I'm unsure if it's the same DataMapper I'm using in Ruby.

What am I overlooking to get DataMapper to find this table?

0

There are 0 best solutions below