首页 \ 问答 \ CakePhp关联有很多(CakePhp association hasMany)

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
更新时间:2021-10-02 12:10

最满意答案

  =======================
  |  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 | |----------| ...
  • 也许这会工作? 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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)