Temat: update composite primary key table problem Let's say we have table user_role('user_id', 'role_id') with data:
[table]
[tr]
[td]user_id[/td][td]role_id[/td]
[/tr]
[tr]
[td]2[/td][td]1[/td]
[/tr]
[/table]
I want to update this record to be:
[table]
[tr]
[td]user_id[/td][td]role_id[/td]
[/tr]
[tr]
[td]2[/td][td]2[/td]
[/tr]
[/table]
In controller file, I have sth like:
I expect it to generate sql like:
However, I got this instead (from the log):
As a result, my record never get updated. I am just wondering how can I get composite primary key table updated, am I missing sth here?
EDIT:
Currently, I can only find a workaround like this: Źródło: yiiframework.com/forum/index.php?showtopic=1733
Temat: unset()ing AR attributes The have something like the following (simplified):
<?php
$b = User::model()->findbyPk(1);
unset($b->password);
$b->save(false);
I expect that to retrieve the user with id 1, unset the password attribute, and then save it again, saving all the fields except the password.
So I expected it to output SQL like the following (assuming I just had a username and password field):
Executing SQL: INSERT INTO `User` (`username`) VALUES (:username)
Instead it tried to store NULL into the password field, which threw a mysql error.
It does however work as expected if it is an insert.
<?php
$b = new User;
$b->password = 'test';
unset($b->password);
$b->save(false);
//OR
$b = User::model()->findbyPk(1);... Źródło: yiiframework.com/forum/index.php?showtopic=562
Temat: many-to-many creation There's no other way. Either use a SQL like in the blog or create another ActiveRecord class for the link table. Źródło: yiiframework.com/forum/index.php?showtopic=2672
zanotowane.pldoc.pisz.plpdf.pisz.plmangustowo.htw.pl
|