Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
@song.likes.select('likes.*, users.*').includes(:user).to_json
只转换类似的对象。有没有办法在 json 结果中包含用户对象?通过 Ruby 或其他方式。
@song.likes.select('likes.*, users.*').includes(:user).to_json(:include => :user)
会做你想做的。
在 Rails-JSON 中,您必须明确指定遍历哪些关联以防止对象树过深和循环引用。