新手问题 多个 model 之间可以调用 scope 方法吗

ckl · March 27, 2014 · Last by rociiu replied at March 27, 2014 · 1804 hits

model A belongs_to :B

model B has_many :A belongs_to :C scope :group_d -> (d_id) { C.d_id: d.id }

model C model D has_many :B has_many : C belongs_to :D

在 view 中我有 A model 对象 test 的 id 并且需要遍历输出: d.name —————————————— c.name a.result c.name a.result ................................

表结构有点复杂,我已经尽量表达了,大拿,谢谢了


class A < ActiveRecord::Base
  belongs_to :b
end

class B < ActiveRecord::Base
  has_many :a
  belongs_to :c
  scope :group_d -> (d_id) { c.d_id: d.id }
end

可以格式化一下 让人更容易看明白

You need to Sign in before reply, if you don't have an account, please Sign up first.