命名装置的问题

发布于 2024-07-23 12:30:43 字数 488 浏览 2 评论 0原文

我正在使用 Rails 2.3,并且有以下关联:

User:
  has_many :photos
  has_many :classifications

Photo:
  belongs_to :user
  has_many :classifications

Classification:
  belongs_to :user
  belongs_to :photo

我对每个模型都有一个固定装置:

users.yml:
tester:
  username: tester
  ...

photos.yml:
bianco:
  id: 1
  user: tester
  ...

classifications.yml:
classificazione_bianco:
  photo: bianco
  user: tester
  ...

所有关联都工作良好,除了分类的 photo_id 被设置为不存在的数字。 为什么命名关联在这种情况下不起作用?

I am working with Rails 2.3 and I have the following associations:

User:
  has_many :photos
  has_many :classifications

Photo:
  belongs_to :user
  has_many :classifications

Classification:
  belongs_to :user
  belongs_to :photo

I have a fixture for each model:

users.yml:
tester:
  username: tester
  ...

photos.yml:
bianco:
  id: 1
  user: tester
  ...

classifications.yml:
classificazione_bianco:
  photo: bianco
  user: tester
  ...

All asociations work well, except from classification's photo_id which is set to a non-existent number. Why the named association doesn't work in this case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云淡月浅 2024-07-30 12:30:44

Rails 不支持命名关联以及直接设置的 ID。

Rails doesn't support named associations along with IDs which have been set directly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文