数据映射器ORM-代码指示符高级关系 [英] Datamapper ORM- Codeigniter Advance Relationship

查看:69
本文介绍了数据映射器ORM-代码指示符高级关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我了解Datamapper的include_join_fields函数的基本使用。我尝试了很多,但没有得到任何结果。

Please help me to understand the basic use of Datamapper's include_join_fields function. I tried it lots of but not getting any results.

我有应用程序像 $ object-> include_join_fields()

我有用户表和国家表。

请帮助我设置$ hasone = array('country_id');关系

Please help me to set $hasone=array('country_id'); relation

我不知道这一切,即使在阅读include_join_fields的文档后没有得到确切的点

I haven't any idea about this all, even not getting the exact point after reading documentation of include_join_fields

任何帮助

感谢

推荐答案

include_join_fields 适用于多对多关系,其中有一个 countries_users 数据透视表,用户可以属于多个国家/地区。

include_join_fields are for many to many relationships, where you have a countries_users pivot table, and users could belong to many country.

例如,您可以选择一个用户 countries ,他属于哪里。但你也存储,用户国家相关。您必须将此额外字段存储在数据透视表中: countries_users

For example, you could take one user, and the countries, where he belongs to. But you also store, how is a user related to that country. You have to store this extra field in your pivot table: countries_users.

所以你的数据透视表, countries_users 看起来像这样,有一个额外的字段 is_he_working_there

So your pivot table, countries_users will look like something like this, with an example extra field is_he_working_there:

id
country_id
user_id
is_he_working_there

当您查询用户的国家/地区时,Datamapper不会将该字段添加为默认值。这里有 include_join_field(),所以如果你调用,Datamapper会将这个字段添加到最终结果。

When you make a query for the user's countries, Datamapper won't add that field default. And here comes the include_join_field(), so if you call that, Datamapper will add this field to the end result.

但是使用 hasone ,它不会产生任何效果,因为你得到用户和其他表字段。此处没有数据透视表,因此不需要include_join_fields()

But with hasone, it won't take any effect, because you get the user, and the other table fields also. No pivot table here, so don't need include_join_fields()

这篇关于数据映射器ORM-代码指示符高级关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆