CakePhp关联有很多(CakePhp association hasMany)
首先,我知道有很多像我这样的问题,但我测试了很多解决方案,阅读文档但我的问题没有解决。
我正在使用Cakephp 2.x.
我得到2个表用户和phone_numbers
CREATE TABLE `users` ( `id` varchar(32) NOT NULL, `user_group_id` int(11) unsigned DEFAULT NULL, `username` varchar(100) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, `salt` text, `email` varchar(100) DEFAULT NULL, `first_name` varchar(100) DEFAULT NULL, `last_name` varchar(100) DEFAULT NULL, `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `user` (`username`), KEY `mail` (`email`), KEY `users_FKIndex1` (`user_group_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `phonenumbers` ( `id` varchar(32) NOT NULL, `user_id` varchar(32) NOT NULL, `phoneNumber` varchar(64) NOT NULL, `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), CONSTRAINT `fk_phonenumbers_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
在我的模型用户中,我得到:
var $hasMany = array( 'LoginToken' => array('className' => 'Usermgmt.LoginToken', 'limit' => 1), 'PhoneNumber' => array('className' => 'PhoneNumber'), );
在我的模型PhoneNumber中,我得到:
var $belongsTo = 'Usermgmt.User';
当我尝试选择我的用户时,我的模型之间没有链接
$this->User->find('all'); array( (int) 0 => array( 'User' => array( 'password' => '*****', 'id' => '1', 'user_group_id' => '1', 'username' => 'admin', 'salt' => '', 'email' => 'admin@admin.com', 'first_name' => 'Admin', 'last_name' => '', 'created' => '2016-03-16 13:49:49', 'Modified' => '2016-03-21 13:04:26', ) ), (int) 1 => array( ..........
我究竟做错了什么? 我需要得到这样的发现
array("User"=>array(my data), "PhoneNumber"=>array(my data) )
谢谢你的帮助。
First of all, I know there is a lot of questions like mine, but I tested a lot of solutions, read the documentation but my problem is not solved.
I'm using Cakephp 2.x
I get 2 tables users and phone_numbers
CREATE TABLE `users` ( `id` varchar(32) NOT NULL, `user_group_id` int(11) unsigned DEFAULT NULL, `username` varchar(100) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, `salt` text, `email` varchar(100) DEFAULT NULL, `first_name` varchar(100) DEFAULT NULL, `last_name` varchar(100) DEFAULT NULL, `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `user` (`username`), KEY `mail` (`email`), KEY `users_FKIndex1` (`user_group_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `phonenumbers` ( `id` varchar(32) NOT NULL, `user_id` varchar(32) NOT NULL, `phoneNumber` varchar(64) NOT NULL, `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), CONSTRAINT `fk_phonenumbers_user` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
In my model User, I get :
var $hasMany = array( 'LoginToken' => array('className' => 'Usermgmt.LoginToken', 'limit' => 1), 'PhoneNumber' => array('className' => 'PhoneNumber'), );
And In my model PhoneNumber I get :
var $belongsTo = 'Usermgmt.User';
When I try to select my users, there is no link between my models
$this->User->find('all'); array( (int) 0 => array( 'User' => array( 'password' => '*****', 'id' => '1', 'user_group_id' => '1', 'username' => 'admin', 'salt' => '', 'email' => 'admin@admin.com', 'first_name' => 'Admin', 'last_name' => '', 'created' => '2016-03-16 13:49:49', 'Modified' => '2016-03-21 13:04:26', ) ), (int) 1 => array( ..........
What am I doing wrong? I need to have my find like this
array("User"=>array(my data), "PhoneNumber"=>array(my data) )
Thanks for your help.
原文:https://stackoverflow.com/questions/38376594
最满意答案
======================= | byte 5 | byte 6 | |----------|----------| | 01010101 | 01010101 | =======================
基本上,它需要字节#5,向左移位8位,产生
0101010100000000
,然后使用按位或运算符将字节6放在零的位置。======================= | byte 5 | byte 6 | |----------|----------| | 01010101 | 01010101 | =======================
Basically, it takes byte #5, shift is 8 bits to the left resulting in
0101010100000000
and then uses the bitwise or operator to put the byte 6 in the place of zeros.
相关问答
更多-
数组的大小是固定的,您必须在创建数组时指定数组的大小。 在你的例子中,你告诉它通过在byte[]之后放置{}来创建一个大小为0的数组。 而是删除{}并在[]之间加一个1 Console.Write("Enter a number: "); byte var1 = byte.Parse(Console.ReadLine()); byte[] byteArray = new byte[1]; byteArray[0] = var1; Arrays are fixed in size, you must spe ...
-
序列化或表示BigFloats很棘手,因为: a。 BigFloat结构使用指针,和b。 指向缓冲区由GMP库控制,GMP库是一个包裹在Julia中的外部库。 因此,作为第一步,这里有一些函数以一种准确且易于操作的方式以文本方式格式化BigFloat: # numbits(a) returns the number of significant digits in a BigFloat # including digits both left and right of floating point. # F ...
-
这应该可以做你想做的事情: var newUrls = urls.map(function (url) { return url.replace(/([a-zA-Z+.\-]+):\/\/([^\/]+):([0-9]+)\//, "$1://$2/"); }); 编辑:看起来URI的模式部分可以包含“+”,“。” 并且。 相应地更改了正则表达式。 请参阅: https : //en.wikipedia.org/wiki/URI_scheme OK, I used your answer and ...
-
======================= | byte 5 | byte 6 | |----------|----------| | 01010101 | 01010101 | ======================= 基本上,它需要字节#5,向左移位8位,产生0101010100000000 ,然后使用按位或运算符将字节6放在零的位置。 ======================= | byte 5 | byte 6 | |----------| ...
-
将数字转换为字节数组(Converting number to byte array)[2022-01-09]
也许这会工作? uint32_t x = 0x0C7E; uint8_t bytes[3]; bytes[0] = (x >> 0) & 0xFF; bytes[1] = (x >> 8) & 0xFF; bytes[2] = (x >> 16) & 0xFF; /* Go back. */ x = (bytes[2] << 16) | (bytes[1] << 8) | (bytes[0] << 0); Maybe this will work ? uint32_t x = 0x0C7E; u ... -
问题是COPYDATASTRUCT应该包含一个指针作为最后一个成员,并且你传递整个数组。 看一下pinvoke.net上的例子: http ://www.pinvoke.net/default.aspx/Structures/COPYDATASTRUCT.html 评论后的更多信息: 鉴于这些定义: const int WM_COPYDATA = 0x004A; [StructLayout(LayoutKind.Sequential)] struct COPYDATASTRUCT { public ...
-
问题很可能是@Hans Passant所提到的 - 如果你想读取二进制数据(即字节而不关心它们如何被编码为文本字符串),你不应该使用SerialPort的String读取方法。 您应该使用Read(Byte[], Int32, Int32)将字节直接输入字节数组。 代码可能如下所示: SerialPort mySerialport = new SerialPort("COM3",9600, Parity.None, 8, StopBits.One); byte[] bytes = new byte[10 ...
-
这只是一些位掩码/移位操作。 例如,如果data[0]包含这些位1111000010101010 ,则会发生以下情况: 1111000010101010 && 0xFF 1111000010101010 && 0000000011111111 ---------------------- 0000000010101010 0000000010101010 << 8 ---------------------- 1010101000 ...
-
如果你知道字节缓冲区中的8个字节确实是双打,那么就这么简单 DoubleBuffer dbls = new ByteBuffer(geomCoords).asDoubleBuffer(); 现在可以使用dbls.get();提取每个点dbls.get(); If you know that the 8 bytes in the bytes buffer are indeed Doubles, then simply DoubleBuffer dbls = new ByteBuffer(geomCoords ...
-
在接受这个作为工作解决方案后,Asker进行了一些进一步的优化。 我在 下面提供了 他们自己的 linked code 供参考: private static long toLong(byte[] value) { ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); final byte val = (byte) (value[0] < 0 ? 0xFF : 0); for(int i = value.length; i < L ...