Dear all, This is a repost of my question, because the first post is considered as thread hijack. I hope i got this right this time.
I have a silly problem in setting up a relationship between 4 models.
I set these 4 models, ComUser, DefJabatan, DefUserRole, DefKelamin. In each model with name started with 'Def', i put a has_one:ComUser relationship. So naturally i have 3 belongs_to relationship in ComUser. I do a simple query in the controller: @users = ComUser.find(:first) and in the view, i simply put a object debug: <%=debug(@users)%>
and I get this:
--- !ruby/object:ComUser attributes: def_jabatan_id: "1" created_at: 2010-11-16 04:31:35 def_user_role_id: "1" gsm: "-" updated_at: 2010-11-16 04:31:35 alamat: "-" username: admin id: "1" def_kelamin_id: "1" password: admin online_status: "2" attributes_cache: {}
I'm getting a feeling that I didn't set the relationship right, because i don't see any attributes addition in the ComUser from the model started with Def-something that i create above..
Am I missing something here, like violating a naming convention or something?
I even tries to alter the table by implicitly put a foreign key in the table for ComUser model using sql statements, and the debug result is still the same. How can i make this relationship work?
Thanks
PS. I put the code snippet that i use for migrating the database and defining the relationship below.
Regards, Arga
ComUser < ActiveRecord::Base belongs_to :DefKelamin belongs_to :DefUserRole belongs_to :DefJabatan Migration: create_table :com_users do |t| t.timestamps t.references :def_jabatan, :null => false t.integer :def_kelamin_id, :null => false t.references :def_user_role, :null => false t.column :username,'varchar(20)', :null => false t.column :password,'varchar(20)', :null => false end
DefJabatan < ActiveRecord::Base has_one:ComUser Migration: create_table :def_jabatans do |t| t.timestamps t.column :jabatan,'varchar(20)', :null => false end
DefUserRole < ActiveRecord::Base has_one:ComUser Migration: create_table :def_user_roles do |t| t.timestamps t.column :role,'varchar(20)', :null => false t.string :description, :null => false t.string :icon end
DefKelamin < ActiveRecord::Base has_one :ComUser Migration: create_table :def_kelamins do |t| t.timestamps t.column :kelamin,'varchar(10)', :null => false end