ruby-on-rails - 命名空间模型 + postgresql 问题

标签 ruby-on-rails postgresql activerecord postgresql-9.3

我不理解 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

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

最佳答案

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

关于ruby-on-rails - 命名空间模型 + postgresql 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20006302/

相关文章:

ruby-on-rails - 在 Rails 4 中查询 Postgres 数组类型的任何成员

ruby-on-rails - 在服务器运行时更​​改 Rails 代码时,Trailblazer 操作中类的父类(super class)不匹配错误

java - 插入具有唯一属性的记录的正确方法

linux - 在 Linux 中用符号链接(symbolic link)替换打开的文件?

sql - 如何在重负载下强制停止长 postgres 查询?

ruby-on-rails - 为新的 ActiveRecord 验证指定错误消息(存在)

ruby-on-rails - "cafe"的 Rails 脚手架多元化不正确

ruby-on-rails - Postgres DB 上的整数超出范围

mysql - 如何查找特定时间之后的所有数据库行

ruby-on-rails - 模型的 Rails 查询部分