dongzhouji4021 2013-09-25 15:50
浏览 13
已采纳

无法在CakePHP中将模型链接在一起

I have 3 models/tables as described

holding

An individual financial holding for a portfolio at a point in time. The fields here are id, date, sedol_id, value


sedol

A table with sedol-specific data.


asset

More general data about an asset. Several sedols can refer to the same asset, but a sedol only refers to one asset.

Here is an overview of the linking:

tables

I'm struggling to associate the models in the Cake. Which model hasOne, hasMany or belongsTo the other. I have tried many combinations but either get a memory exhausted error (infinate loop?) or an SQL error where the joining is not done correctly.

Here's an example in case my question isn't clear.

Let's say there's a holding records which is shares in Vodafone PLC. this might appear in the holdings table like

     id   | sedol  |   date     | value
   ---------------------------------------
   123456 | 16GWD5 | 2013-09-15 | 15456.25

Now this holding's sedol refers to the Sedol table which has share-specific info. Among this info in the SEDOL table is an ips_asset_id which refers to the company itself. E.g. Vodafone may have several different classes of shares (represented by sedols) but the fundementals of the company equity would be in the ips_assets table.


EDIT: OK I think I have solved the joins but when I query the database to find all the sedols it tries to retreive every holding, when all I want to do is get the data from the holdings table. Any ideas?

  • 写回答

1条回答 默认 最新

  • dongyanjing5975 2013-09-25 16:17
    关注

    In your example:

    • Holding belongsTo Sedol
    • Sedol belongsTo IpsAsset

    However, I don’t know enough about your models to know whether the relationships the other way are would be a hasOne or hasMany.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥50 vue router 动态路由问题