表
User(id)
Profile(id, *user_id*, type)
Attribute(id, *attribute_name_id*, value)
AttributeName(id, name)
ProfileAttribute(id, *profile_id*, *attribute_id*)
关系
关系设置正确(并且双向,hasMany/belongsTo)。
User hasMany Profile
Profile hasMany ProfileAttribute
Attribute hasMany ProfileAttribute
(could be written Profile hasMany Attribute through ProfileAttribute)
AttributeName hasMany Attribute
目标
对于指定的用户 ID,在用户模型中有一个 find(),我只想要以下字段,如下所示:
$results[Profile.type][AttributeName.name][Attribute.value]
甚至可以检索这样排列的结果吗?我一直在玩 Find and Containable 几个小时,但是,第一次尝试用 Cake 做这样复杂的事情,我无法掌握它的窍门。
谢谢!
编辑
我现在得到了这些结果,这是我所需要的,但与上面所需的格式相去甚远——它可以作为查找的一部分完成,还是需要在之后进行排序?