0

我需要获取所选订单的配置文件(打印订单)。

我的profiles表有一user_id列,我的prints表也有一user_id列。

Profile模型Print模型belongs_to :user

打印型号:

class Print < ActiveRecord::Base
  attr_accessible :comment, :document
  belongs_to :user
end

和,轮廓模型:

class Profile < ActiveRecord::Base
  attr_accessible :address, :name, :phone
  belongs_to :user
  has_many :prints
end

如何根据用户从配置文件中获取打印数据?

4

1 回答 1

1

假设你有print对象 &user has one profile然后

print.user.profile

Profile has_many :prints也是多余的,你可以直接使用

print.profile
于 2013-05-22T14:20:01.760 回答