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.
我有一个名为 Vehicle 的模型。我如何通过 rails 控制台找到 Vehicle 的父级,即
vehicle = Vehicle.find(1) vehicle.parent vehicle.parent_id.present?
“父”仅适用于类,而不适用于实例。所以,对于班级家长
vehicle.class.parent
如果您的意思是关联而不是类,请使用reflections
reflections
vehicle.reflections