[eluser]The Mask[/eluser]
Hi,
I have a model Client that has a one-to-many relationship with Sites. So when I wish to add a new Site, I need to select the Client from a dropdown. I can get the dropdown to render but the values of the options don't match the Ids in the table. Instead, they are populated as "0", "1".. etc. Do you know why I'm not getting the correct Ids?
Site model
class Com3_site extends Datamapper {
var $has_one = array( 'com3_client' );
var $validation = array(
'com3_client_id' => array (
'label' => 'Client',
'type' => 'dropdown'
),
etc...
);
etc...
Client model
class Com3_client extends Datamapper {
var $has_many = array( 'com3_site' );
etc...
Controller code
$s = new Com3_site();
$c = new Com3_client();
$c->get();
$this->data['form_fields'] = array( 'com3_client_id' => array( 'list' => $c ),
etc...);
$this->data['s'] = $s;
$this->load->view( $view, $this->data );
View code
echo $s->render_form( $form_fields );
If I look at the generated HTML for the dropdown, it looks like this...
<select name="com3_client_id" id="com3_client_id">
<option value="0">Client 1</option>
<option value="1">Client 2</option>
</select>
But in the database, Client 1 has an ID of 15 and Client 2 has an ID of 16. So any ideas why the values are set to "0" and "1" and not the IDs?
Thanks