Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Codeigniter的Datamapper中将关系映射到通用模型_Codeigniter_Codeigniter Datamapper - Fatal编程技术网

在Codeigniter的Datamapper中将关系映射到通用模型

在Codeigniter的Datamapper中将关系映射到通用模型,codeigniter,codeigniter-datamapper,Codeigniter,Codeigniter Datamapper,我在一个由Codeigniter的Datamapper库支持的系统中有许多不同的模型,如帖子和页面,我对向系统添加喜欢的内容和评论很感兴趣。在我看来,喜欢和评论可以应用于任何扩展Datamapper的模型。我将如何定义这样的关系(将任何类型的模型的喜好以及评论保留在同一个表中)?我倾向于为喜好和评论创建单独的表。我通常创建这种模式: Likes ----- id // autoincrement obj // the related model (the name of the

我在一个由Codeigniter的Datamapper库支持的系统中有许多不同的模型,如帖子和页面,我对向系统添加喜欢的内容和评论很感兴趣。在我看来,喜欢和评论可以应用于任何扩展Datamapper的模型。我将如何定义这样的关系(将任何类型的模型的喜好以及评论保留在同一个表中)?

我倾向于为喜好和评论创建单独的表。我通常创建这种模式:

Likes
-----
id      // autoincrement
obj     // the related model (the name of the model that is being liked)
obj_id  // the foreign key
user_id // the user id that liked the model object
created // timestamp
updated // timestamp
然后是评论表:

Comments
--------
id       // autoincrement
obj      // the related model (same as above)
obj_id   // the foreign key
message  // the comment itself
user_id  // the user id that commented on the model object
created  // timestamp
updated  // timestamp

这也是我所想的。这个关系如何用Datamapper has_one and has_many relations来表示(obj/obj_id上的复合键如何表示)?