dear all,
This may sound stupid, but I'm confused in creating the model relationship.
I set these 4 models:
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
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
In the controller, I put a simple query:
@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 from the model started with Def-something that i create
above..
Am I missing something here? I've been staying wake all night to sort this thing
out, with no success.
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
Regards,
Arga