【发布时间】:2013-11-15 16:50:42
【问题描述】:
对 PostgreSQL 和我不理解的命名空间模型有疑问。
@photos = Profile::Photo.where(:attachable_id => id)
这会抛出一个:
!! #<ActiveRecord::StatementInvalid: PG::UndefinedTable:
ERROR: relation "profile_photos" does not exist
LINE 1: SELECT "profile_photos".* FROM "profile_photos" WHERE "prof...
^
: SELECT "profile_photos".* FROM "profile_photos"
WHERE "profile_photos"."attachable_id" = 1>
我有一个模型 app/models/profile/photo.rb,例如:
class Profile::Photo < ActiveRecord::Base
mount_uploader :file, PhotoUploader
belongs_to :attachable, :polymorphic => true belongs_to :user,
:dependent => :destroy #belongs_to :profile, :foreign_key =>
'attachable_id', :dependent => :destroy
它说关系不正确,但这在命名模型之前完美运行。我在这里忽略了什么?
【问题讨论】:
-
数据库中的表的名称是什么?你之前提到它工作得很好,如果不是,你可能需要使用
set_table_name,实际上,profile_photos -
我的表好像重命名为profiles_photos,我认为它必须是多重的,现在不确定
标签: ruby-on-rails postgresql activerecord postgresql-9.3