在 Yii 的 CActiveRecord 中,我们如何返回 SET 数据类型为整数的属性
请看下面的例子:
mysql> SELECT rowid, myset, myset+0
-> FROM set_test;
+-------+-----------------------+---------+
| rowid | myset | myset+0 |
+-------+-----------------------+---------+
| 1 | Sports | 2 |
| 2 | Travel,Sports | 3 |
| 3 | Travel,Dancing | 5 |
| 4 | Travel,Sports | 3 |
| 5 | Travel,Sports,Dancing | 7 |
| 6 | Travel,Dancing | 5 |
| 7 | Sports | 2 |
| 8 | Travel,Dancing | 5 |
+-------+-----------------------+---------+
8 rows in set (0.00 sec)
在 Yii 中,使用 CActiveRecord->myset
总是返回一个用逗号分隔的字符串。 我怎样才能像上面那样返回一个integer
?
Please look at below example:
mysql> SELECT rowid, myset, myset+0
-> FROM set_test;
+-------+-----------------------+---------+
| rowid | myset | myset+0 |
+-------+-----------------------+---------+
| 1 | Sports | 2 |
| 2 | Travel,Sports | 3 |
| 3 | Travel,Dancing | 5 |
| 4 | Travel,Sports | 3 |
| 5 | Travel,Sports,Dancing | 7 |
| 6 | Travel,Dancing | 5 |
| 7 | Sports | 2 |
| 8 | Travel,Dancing | 5 |
+-------+-----------------------+---------+
8 rows in set (0.00 sec)
With Yii, using CActiveRecord->myset
always returns a string which is separated by comma.
How could I return as a integer
like above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以覆盖活动记录类中的 getter 方法或创建一个新方法。
另外,获取这些整数值的方式应该根据您的需要进行调整,上面的示例只是伪代码。
You could overwrite the getter method in your active record class or create a new one.
Also the way of getting these integer values should be adjusted to your needs, the above example is just pseudo-code.