Hi everybody!
I use PostgreSQL database in my project.
In example below $mydata->subscriber_sms is integer[] type
public function actionSubscriber()
{
$mydata=Mydata::model()->findbyPk($_POST['id']);
if (isset($_POST['Mydata']))
{
$mydata->attributes=$_POST['Mydata'];
$mydata->subscriber_sms=<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?
if ($mydata->save())
//redirection
}
$this->render('subscriber',array(
'user'=>$mydata,
));
}
Which way can I assign value for attribute of array type?
I try $mydata->subscriber_sms=’{1,2,3}’;
It does not work
Thanks
Hi dude,
I think that you need separate this datas in another table and
make a relation between this tables.
Like this:
on table Mydata will have a field sms_id, and on table sms will have three fields id, mydata_id and sms_number.
The relations look alike this:
Table Mydata has_many sms table.
Then, the data will be more normalized on database. What do you think about?
To create additional table is classic way, but why array types exist?
If I use direct query like
update Mydata set subscribers_sms=’{1,2,3}’ where …
it will be done
Maybe Active Record can not do it.
Ok , I understood right now.
When you try to store a the array on subscribers_sms field, the application show any error?
The application can store some thing on database? what?
when $mydada->save()
i accept this error
"subscriber_sms" is of type integer[] but expression is of type integer
now i simply form direct query like update mydata set subscriber_sms=’{1,2…}’ where …
Other words - problem’s over
Thanks for support
megahertz
(Megahertz)
November 10, 2009, 5:45am
6
What query (include bind parameters) is generated by Yii when you save data with ActiveRecord?
in log I have this:
UPDATE "base"."mydata" SET "id"=:yp0, "login"=:yp1, "name"=:yp2, "password"=:yp3, … "subscriber_sms"=:yp41, … WHERE "base"."userlist"."id"=-1
I do it without AR
try
{
$attr=$_POST['Mydata'];
$sql='update base.userlist set';
$v='';
for($i=1; $i<=Mydata::SUBSCRIBER_SMS_COUNT; $i++)
{
if($attr['sms'.$i]==1) $v.=($v==''?"'{":',').$i;
}
$v=$v==''?'null':$v."}'";
$sql.=' subscriber_sms='.$v;
$sql.=' where id=:id_userlist';
$command=Yii::app()->db->createCommand($sql);
$command->bindValue(":id_userlist", Yii::app()->user->id);
$command->execute();
Yii::app()->user->setFlash('EVENT','Data saved');
$this->refresh();
}
catch (Exception $e)
{
...
}
megahertz
(Megahertz)
November 10, 2009, 9:28am
8
You can enable CDbConnection::enableParamLogging to see what value is set for yp41. I didn’t work with PDO_PGSQL, may be it support array binding and you can try to write $mydata->subscriber_sms = array(1,2,3). But may be PDO_PGSQL can not support array type for fields. If it’s true, you can override CActiveRecord::insert() and CactiveRecord::update() methods for model or continue to use direct queries.
$mydata->subscriber_sms = array(1,2,3) does dot work
it is realy PDO_PGSQL bug
Parameter :yp41 for attribute $mydata->subscriber_sms always is integer datatype, and tail of the bug from PDO