how to handle has_many option in custom module
hi i am using the latest version of fuel :
i have used a relation like as follow
public $has_many = array('speaker_id' => array('model' => array( FUEL_FOLDER => 'speakers_model' ),'where' => array('is_disabled' => 0)));
it is generation a filed multi select every thing is quit fine if i select a single option but it is giving error while i am selecting multiple option. like as follow :
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: core/MY_DB_mysqli_driver.php
Line Number: 277
i have tried : following function's in model
function save($record=array(), $validate=TRUE,$ignore_on_insert=TRUE, $clear_related=NULL)
{
if(isset($record['speaker_id']))
{
$record['speaker_id']=(is_array($record['speaker_id']))?implode(',', $record['speaker_id']):$record['speaker_id'];
}
return parent::save($record, $validate, $ignore_on_insert, $clear_related);
}
function form_fields($values = array(),$related=array())
{
if(isset($values['speaker_id']))
{
$values['speaker_id']= explode(',', $values['speaker_id']);
}
$fields = parent::form_fields($values);
return $fields;
}
this fixed the error but not showing the selected items while editing
in this table speaker_id is varchar
what is the mistake i am doing while using the normal way - can one help me with it ???? what way should i take to resolve it ???
Comments
http://stackoverflow.com/questions/37856056/how-to-handle-has-many-option-in-custom-module
public $has_many = array('speaker_id' => array('model' => 'speakers_model', 'where' => array('is_disabled' => 0)));
Note that the array(FUEL_FOLDER => 'speakers_model') was replaced with just 'speakers_model' which refers to the main application/model folder.
public $has_many =array('speaker_id' => array('model' => array( 'events'=>'speakers_model'), 'where' => array('is_disabled' => 0)));
but the condition have not changed :
it doing the add save function properly
but while editing it is not showing the selected options ...as selected ...
public $has_many =array('speaker_id' => array( 'events'=>'speakers_model', 'where' => array('is_disabled' => 0));
if(isset($record['speaker_id']))
{
$record['speaker_id']=(is_array($record['speaker_id']))?implode(',', $record['speaker_id']):$record['speaker_id'];
}
from save
and $values['speaker_id']= explode(',', $values['speaker_id']); from orm_fields function and just by adding the fild to $serialized_fields