gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:32:37 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com