I have the following models with names:
class FaceData::PoolMembership < ActiveRecord::Base
self.table_name = 'face_data_pool_memberships'
belongs_to :pool, class_name: 'FaceData::Pool'
belongs_to :photo
end
class FaceData::Pool < ActiveRecord::Base
self.table_name = 'face_data_pools'
end
class Photo < ActiveRecord::Base
has_many :pool_memberships, class_name: 'FaceData::PoolMembership'
has_many :pools, through: :pool_memberships, class_name: 'FaceData::Pool'
end
And the database schema is as follows:
create_table "face_data_pool_memberships", force: true do |t|
end
create_table "face_data_pools", force: true do |t|
end
The application works fine, but when I boot (server, rake task, etc.) I get the following error:
PG::UndefinedTable: ERROR: relation "pool_memberships" does not exist
LINE 5: WHERE a.attrelid = '"pool_memberships"'::regc...
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"pool_memberships"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
This only happens in production (not in the development environment) and looks as if it does not affect the runtime (the application continues to run finely polarized queries using the correct table name).
Note that the application has other FaceDatamodules and classes with names in the namespace. Setting table_name_prefixexplicitly to an empty line does not cause the error to disappear.
I guess this has something to do with loading file order or association has_many :through. Any tips?