I have field "File", it receive file and saving it, decode fileinfo in json for saving in DB. When loading from DB, json becomes object.
Now i need additional fields, aka "attributes", in this object, not a additional field in DB, example "author", for save it in JSON. I think, create field "author" as "String" field from field "File" with attribute "in_db = false", with specific name. Sample
class Model_Test{
public static function initialize($meta)
{
$fields = array(
'attachment' => Jelly::field('file');
);
$meta->fields($fields);
}
}
Field 'attachment' must create self, and additional field '__attachment_author':
'__attachment_author' = Jelly::field('string', array('in_db'=>false));
When i upload file.
$_FILES['attachment'] = [upload file array];
$_POST['__attachment_author'] = 'Upload master';
$m = Jelly::factory('test');
$m->set($_FILES+$_POST);
$m->save();
So, in field 'attachment' i get the value from additional field '__attachment_author' , and set it to result JSON, in method 'save';
But in this case i have a 2 problems:
- When loading data from DB, i can't set value to additional field, because setter in Jelly_Field don't have current model instance.
- When i change additional field ('__attachment_author'), i need resave object, but field 'attachment' is not changed, and mehod 'save' in 'attachment' field don't called.
Maybe it's wrong way?
I have field "File", it receive file and saving it, decode fileinfo in json for saving in DB. When loading from DB, json becomes object.
Now i need additional fields, aka "attributes", in this object, not a additional field in DB, example "author", for save it in JSON. I think, create field "author" as "String" field from field "File" with attribute "in_db = false", with specific name. Sample
class Model_Test{ public static function initialize($meta) { $fields = array( 'attachment' => Jelly::field('file'); ); $meta->fields($fields); } }Field 'attachment' must create self, and additional field '__attachment_author':
'__attachment_author' = Jelly::field('string', array('in_db'=>false));When i upload file.
$_FILES['attachment'] = [upload file array]; $_POST['__attachment_author'] = 'Upload master'; $m = Jelly::factory('test'); $m->set($_FILES+$_POST); $m->save();So, in field 'attachment' i get the value from additional field '__attachment_author' , and set it to result JSON, in method 'save';
But in this case i have a 2 problems:
Maybe it's wrong way?