Topic: Foreign Key fields not addressed in views
Hi. I am definitely a newbee to RoR. I'm looking at porting a Web application from Java (using JDeveloper and Oracle's lightweight ADF data connections. I'm having a very basic problem in understanding table relationships under RoR (using MySQL).
The app is an HR system, allowing multiple client companies, with each company having numerous employees, and each employee having several sub-tables of various data (i.e. dependents, benefits, payroll deductions, training courses, jobs etc).
I set up the client (against "clients" table with an 'id') model with "has_many :employees:. I set up the employee model (against "employees" table with and 'id' and a fk 'client_id') as
"belongs_to :client".
I initially used controllers with dynamic "scaffolding". I then restarted after "generating" scaffolds in order to actually see more of what was going on. I've tried it both with and without the foreign keys defined in the database tables.
The views resulting from scaffolding do NOT reflect the foreign key fields.
To create a new employee, how do I assign the client_id? The model, unlike my Java and other experience, does not reflect what fields are there. Is the foreign key field there? Included in the model at runtime? Is is editable?
If I wanted a master-detail form (i.e. a listing of the top-level table of the several client companies and, upon selection, a detail listing of all employees of that company) how can I get one readily?
I know this is probably a VERY base issue and I'm sorry to seem soooo stupid. I'm sure it's a factor of my prior experience and vantage point and I just can't readily grasp the RoR view. But I sure would like to. I'm already loving RoR.
Thanks