gpt4 book ai didi

php - CakePHP 关联模型返回 null?

转载 作者:行者123 更新时间:2023-11-29 13:17:57 25 4
gpt4 key购买 nike

我在随机返回具有 NULL 值的变量时遇到问题。

我有这个模型关联结构:

Truck   $hasOne  Chassis
Chassis $hasMany Make
Chassis $hasMany Model
Truck $hasOne Type

随机结果将具有类型的空结果或品牌和型号的空结果,但其他结果将具有正确的结果..

0 (array)
Truck (array)
Chassis (array)
id 1
make_id 2
model_id 2
title Basic Chassis
description This Basic Chassis is good for a lot of things, but advanced stuff is not one..
Truck_make (empty)
Truck_model (empty)

1 (array)
Truck (array)
Chassis (array)
id (null)
make_id (null)
model_id (null)
title (null)
description (null)

在上面,您可以看到 2 辆卡车已装载,第一辆卡车的底盘已装载,以及品牌和型号 ID,但没有品牌和型号的数组。第二辆车也没有负载..

这是 MySQL Workbench 关联的屏幕截图: http://d.pr/i/JgMt

这些是被调用的查询。

Query   Affected    Num. rows   Took (ms)   Actions
SELECT `Truck`.`id`, `Truck`.`chassis`, `Truck`.`type`, `Truck`.`title`, `Truck`.`ref`, `Truck`.`hide_truck`, `Truck`.`featured_gallery`, `Truck`.`featured_home`, `Truck`.`created`, `Chassis`.`id`, `Chassis`.`make_id`, `Chassis`.`model_id`, `Chassis`.`title`, `Chassis`.`description`, `Type`.`id`, `Type`.`title`, `Type`.`desc` FROM `douglass_cake`.`trucks` AS `Truck` LEFT JOIN `douglass_cake`.`chassis` AS `Chassis` ON (`Chassis`.`id` = `Truck`.`id`) LEFT JOIN `douglass_cake`.`types` AS `Type` ON (`Type`.`id` = `Truck`.`id`) WHERE 1 = 1
SELECT `Truck_make`.`id`, `Truck_make`.`make`, `Truck_make`.`hide_make` FROM `douglass_cake`.`truck_makes` AS `Truck_make` WHERE `Truck_make`.`id` = (1)0
SELECT `Truck_model`.`id`, `Truck_model`.`model`, `Truck_model`.`hide_model` FROM `douglass_cake`.`truck_models` AS `Truck_model` WHERE `Truck_model`.`id` = (1)

最佳答案

我解决了这个问题。看起来 MySQL Workbench 写入的表的偏移量为 2 而不是 1。Cakephp 期望默认偏移量,因此当行返回到 cakephp 时,它从 1 开始读取,而 MySQL 被告知从 2 开始。修复。愚蠢的错误

关于php - CakePHP 关联模型返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21227929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com