2013-11-15 52 views
1

PostgreSQL和我不明白的名称空间模型有问题。命名空间模型+ 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> 

我有一个模型的应用程序/模型/资料/ 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 

它说的关系是不正确的,但这个工作完美地在命名空间模型之前。我在这里忽略了什么?

+0

db中表的名称是什么?你提到它以前完美的工作,你可能需要使用'set_table_name',如果它不是,实际上,'profile_photos' – trh

+0

看来我的表被重命名为profiles_photos,我认为它必须是多个s不知道现在 – Rubytastic

回答

1

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