简体   繁体   English

有人可以解释一下 codeigniter 的杂货杂货中的 set_relation() 和 set_relation_n_n 是做什么的吗?

[英]Can someone explain what set_relation() and set_relation_n_n in grocery crud for codeigniter does?

I'm trying to integrate the grocery crud a system but I don't understand what set_relation my database design already has relations so I want to know how this will help, or rather what it does.我正在尝试将杂货杂货集成到一个系统,但我不明白我的数据库设计已经有什么 set_relation 关系,所以我想知道这将如何提供帮助,或者更确切地说它有什么作用。 I can't understand the docs' examples.我无法理解文档的示例。

DOCS EXAMPLES文档示例

void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] ) Quick Description: Set a relation 1-n database relation. void set_relation( string $field_name , string $related_table, string $related_title_field [, mixed $where [, string $order_by ] ] ) 快速说明:设置关系 1-n 数据库关系。 Set a relation 1-n database relation.设置关系 1-n 数据库关系。 This will automatically create a dropdown list to the fields and show the actual name of the field and not just a primary key to the list.这将自动为字段创建一个下拉列表,并显示字段的实际名称,而不仅仅是列表的主键。 An example of this:这方面的一个例子:

$crud->set_relation('user_id','users','username');

You can have as many fields you like to call from the other table and the syntax is really simple.您可以从另一个表中调用任意多个字段,并且语法非常简单。 Just at the 3rd field you will have the symbol { and } .就在第三个字段,您将看到符号 { 和 } 。 So it will be for example:所以它将是例如:

$crud->set_relation('user_id','users','{username} - {last_name} {first_name}');

And you can have whatever syntax or symbols you like.你可以拥有任何你喜欢的语法或符号。 So for example you can have:例如,您可以拥有:

$crud->set_relation('user_id','users','{username} ( {last_name} {first_name} )');

The parenthesis is just to show you that you can insert whatever symbol you like.括号只是为了向您表明您可以插入任何您喜欢的符号。

the $crud->set_relation function used to represent [ one to many relation] $crud->set_relation 函数用来表示[一对多关系]

and the $crud->set_relation_n_n function used to represent the [ many to many relation]和 $crud->set_relation_n_n 函数用于表示 [多对多关系]

for example the gender may be male or female exclusively It cannot be both So we can represent it using set_relation;例如,性别可能是男性或女性,不能同时是,所以我们可以使用 set_relation 来表示它; but the student courses for example may be more than one and need new table to connect studentID with many coursesID's like this example :但是例如学生课程可能不止一个,并且需要新表来将学生 ID 与许多课程 ID 连接起来,如下例所示:

***tblStudents***
id      name
1       Jack
2       John
-------------------------------
***tblCourses***

id   courseName
1     Math
2     Science
3     Statistics
4     Geographic
-------------------------------
***tbl_stu_course_m_m***
 
studentID  courceID
1            1
1            2
1            4

in this case Jack with id 1 has relation with three courses from total (four courses) if we represent them in malty select options in insert or edit mode, will be like this: Courses:在这种情况下,id 为 1 的 Jack 与总共(四门课程)中的三门课程有关系,如果我们在插入或编辑模式下用麦芽选择选项表示它们,将是这样的: 课程:

  • Math数学
  • Science科学
  • statistics[not selected]统计[未选择]
  • Geographic地理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM