【发布时间】:2018-07-20 11:45:40
【问题描述】:
我正在开发一个具有三个模型的 Rails 应用程序。
class User < ApplicationRecord; end
class Share < ApplicationRecord; end
class Note < ApplicationRecord; end
create_table :users do |t|
t.timestamps
end
create_table :notes do |t|
t.integer 'user_id'
t.text 'title'
t.text 'short_description'
t.string 'name'
t.timestamps
end
create_table :shares do |t|
t.integer 'user_id'
t.integer 'receiver_id'
t.integer 'note_id'
t.timestamps
end
我怎样才能在它们之间建立关联,这样我才能得到
- 用户 A 共享的笔记。
- 用户 A 收到的备注。
- 用户 A 创建的笔记。
【问题讨论】:
标签: ruby-on-rails activerecord associations