I’m creating a small timesheet application. Timesheets have athletes, and each athlete has personal split times (like in running, or race car driving)
An Athlete hasMany Run, a Run belongsTo Athlete, An Athlete hasAndBelongsToMany Timesheets (and vice versa). A Timesheet hasMany Run, and finally a Run belongsTo Timesheet.
When I’m adding new runs in my view, I’m unable to get anything but the athlete_id in the select box. I’d really like to have their names instead. Instead of
<?php echo $run['athlete_id'];?>, I’ve tried <?php echo $athlete['Athlete']['last_name'] ?> but I can’t seem to get it to work. Any help would be greatly appreciated. Thanks!
Without knowing exactly how you are building your forms/data it is hard to tell, but how I would do it is.
In the RunController add
and then in the View use this form helper line.
This should work, there is also a way to use ‘compact’ to make it a little easier but the above should work fine.
—- BEGIN EDIT —-
I did a little research and found the compact method.
In your RunController use
and then in your View use
and the form helper will automatically find the compacted Athlete array and build the select.
—- END EDIT —-
Hope this helps.
Cheers,
Dean