1

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

它说关系不正确,但这在对模型进行命名空间之前非常有效。我在这里忽略了什么?

4

1 回答 1

1

问题是不正确的命名模型,我重构以更正复数格式并正确重命名表,从而解决了问题。

于 2013-11-16T16:39:44.543 回答