如何检查关联是否在 Rails 控制台上有效


 =>s = User.new
 => #<User id: nil, first_name: nil, last_name: nil, email: nil, address: nil, type_of_user: nil, created_at: nil, updated_at: nil> 
2.2.0 :015 > o.publisher_id = s
 => #<User id: nil, first_name: nil, last_name: nil, email: nil, address: nil, type_of_user: nil, created_at: nil, updated_at: nil> 
2.2.0 :016 > o.publisher_id = 6
 => 6 
2.2.0 :017 > s = User.create(:first_name => "Bostnss")
   (0.2ms)  BEGIN
   (0.2ms)  ROLLBACK
 => #<User id: nil, first_name: "Bostnss", last_name: nil, email: nil, address: nil, type_of_user: nil, created_at: nil, updated_at: nil> 
2.2.0 :018 > o.publisher_id = 5
为此,

您必须首先知道您正在使用哪些关联,您必须应用此法典在我的应用程序中,我有三个模型用户,订单和文章

所以为了检查关联,我使用它

a = 文章.新插入数据后,然后

使用命令

A.雷亚洛德

然后

a.用户 [我在关联中给出的名称]如果它有效,则意味着关联有效

相关内容

最新更新