[英]How do I include the user objects n the json result?
@song.likes.select('likes.*, users.*').includes(:user).to_json
Only converts the like objects. 仅转换相似的对象。 Is there a way to include the user objects in the json result? 有没有办法在json结果中包含用户对象? Via Ruby or other. 通过Ruby或其他方式。
@song.likes.select('likes.*, users.*').includes(:user).to_json(:include => :user)
Would do what you want. 会做你想要的。
In Rails-JSON you have to explicitly specify which associations get traversed to prevent too deep object trees and circular references. 在Rails-JSON中,您必须明确指定遍历哪些关联,以防止对象树和循环引用太深。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.