Datamapper ORM- Codeigniter Advance Relationship

时光毁灭记忆、已成空白 提交于 2019-12-13 03:36:39

问题


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.

I have application like $object->include_join_fields()

I have User table and Country table.

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

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

Any help will appricate

Thanks


回答1:


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

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.

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

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.

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()



来源:https://stackoverflow.com/questions/32866324/datamapper-orm-codeigniter-advance-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!