2013-05-20 100 views
0

我有以下關係:Ruby on Rails的,belongs_to的不工作

class GroupsNorm < ActiveRecord::Base 
    attr_accessible :group_name, :file_names 
    has_many :platformas 
end 

class Platforma < ActiveRecord::Base 
    attr_accessible :file_name, :norm_type, :groups_norm_id 
    belongs_to :groupsnorm 

end 

在控制檯:

A = Platforma.new(:FILE_NAME => 「kkkkk.cel」:groups_norm_id => 9)
a.save
b = GroupsNorm.find(9)

=> #<GroupsNorm id: 9, group_name: "aaaaaa", file_names: "/system/Files/aaaaaa_cel_files...", created_at: "2013-05-20 13:37:14", updated_at: "2013-05-20 13:37:14"> 

b.platformas

[#<Hgu133a id: 1, groups_norm_id: 9, file_name: "aaa.cel", created_at: "2013-05-20 21:31:05", updated_at: "2013-05-20 21:31:05">, #<Hgu133a id: 2, groups_norm_id: 9, file_name: "kkkkk.cel", created_at: "2013-05-20 21:47:24", updated_at: "2013-05-20 21:47:24">, #<Hgu133a id: 3, groups_norm_id: 9, file_name: "kkkkk.cel",created_at: "2013-05-20 21:54:37", updated_at: "2013-05-20 21:54:37">] 

所以,一切都很好,我們的新紀錄也一樣。 但是,當我打電話:

irb(main):011:0> a.groupsnorm 
=> nil 

爲什麼它不告訴我,有ID == 9 GroupsNorm記錄?

在此先感謝

回答

相關問題