新手问题 谁能解释以下 has_many 的问题

sanvi · October 08, 2012 · Last by woaigithub replied at October 09, 2012 · 2015 hits

Post has_many :wish_users, :class_name => "Account"

我通过这个方法把 user 插入进去 def push_wish_user(uid) binding.pry return false if self.wish_user_ids.include?(uid) self.push(:wish_user_ids,uid)
end

那么为什么每次 self.wish_user_ids 都是空数组

我查看了 mongo 是有值的

而且在 view 上,wish_users 也是空

mongoid 不支持吧,用 collect 做吧,文档没找着。 mysql 可以http://guides.rubyonrails.org/association_basics.html#has_many-association-reference

#1 楼 @ruby_sky 好像多对多可以,刚换了下,能拿到值,如果单向 has_many,能保存,但没值

一对多的关系。

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