Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
SaveAttribute in Model
S
✭✭
Developing apps by using Garden (Vanilla) I noticed that very often I need field "Attributes" in table structure and of cousre need method like SaveAttribute (so I copy-pasted SaveAttribute() code from UserModel with a little changes).
Maybe is reasonable to add SaveAttribute() method to Gdn_Model class?
It will look like:
Maybe is reasonable to add SaveAttribute() method to Gdn_Model class?
It will look like:
public function SaveAttribute($RowID, $Name, $Value = '') {
if (!isset($this->Schema)) $this->DefineSchema();
// TODO: need make sure that $RowID is not multiple primary key
$FieldName = $this->PrimaryKey;
$Row = $this->SQL
->Select('Attributes')
->From($this->Name)
->Where($FieldName, $RowID)
->Get()
->FirstRow();
if(!$Row) throw new Exception(Gdn::Translate('ErrorRecordNotFound'));
$Values = Format::Unserialize($Row->Attributes);
if(!is_array($Values)) $Values = array();
if(!is_array($Name)) $Name = array($Name => $Value);
$Values = Format::Serialize(array_merge($Values, $Name));
return $this->SQL
->From($this->Name)
->Set('Attributes', $Values)
->Where($FieldName, $ID)
->Put();
}
0
Comments