您好我正在设计一个基于评论的数据库设计。我在这部分遇到问题 我怎样才能检查两个用户是否在社交旅行中相互评价。就像我们在工作完成时有一个正常工作的评审系统,雇主和自由职业者可以给对方提供相同的评论,就像我想在这里实施一样雇主没有给自由职业者审查,然后他会在屏幕上显示对自由职业者的反对工作的反馈。 同样在我的应用程序中的区别是在我的应用程序中这是旅行
我有旅行表,携带请求表,项目和评论表
1- Trip table will have trips of users
2- Registered users can requests items on a trip
3-When the registered user go to the other user created trip page then he can send the request to user against that trip to carry an item for him .
then an entry will be inserted in a carry_request table by sender_id which has requested the item and receiver id the user which has received the requests.
现在我在设计评论表时遇到了问题 我该如何决定哪个用户已经向其他用户提供了审核,哪些用户没有 我们还会在每个carry_request的评论表中有2个条目进行审核,因为对于1个进位请求,我们将有2个评论来自发件人和收件人。
这是我的查询
select i.id as item_id,t.id as trip_id,us.id as sender_user_id,ur.fname as receiver_fname
from carry_requests cr
INNER JOIN users us on cr.sender_id = us.id
INNER JOIN users ur on cr.receiver_id = ur.id
INNER JOIN trips t on cr.trip_id = t.id
INNER JOIN items i on cr.item_id = i.id
where cr.sender_id = 24;
有了这个查询我得到了针对这个用户的所有记录都很好,直到我必须找出哪个发件人没有给收件人审查或哪个收件人没有给发件人审查,以便在屏幕上显示他们的请假审查按钮。 这是我的carry_requests表
CREATE TABLE IF NOT EXISTS `carry_requests` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sender_id` int(11) NOT NULL,
`receiver_id` int(11) NOT NULL,
`trip_id` int(11) NOT NULL DEFAULT '0',
`item_id` int(11) NOT NULL,
`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`is_sender_reviwed` int(11) NOT NULL DEFAULT '0',
`is_receiver_reviwed` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
CREATE TABLE `trips` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`uid` INT(11) NOT NULL,
`from_location` VARCHAR(255) NOT NULL,
`to_location` VARCHAR(255) NOT NULL,
`departDTTM` DATE NOT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE IF NOT EXISTS `items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`status` int(11) NOT NULL DEFAULT '0',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
评论表
CREATE TABLE `reviews` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`trip_id` INT(11) NOT NULL,
`reviewer_id` INT(11) NOT NULL DEFAULT '0', which has given the review
`user_id` INT(11) NOT NULL DEFAULT '0', to whom review was given
`rating` INT(11) NOT NULL DEFAULT '0',
`review` TEXT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
答案 0 :(得分:1)
以下是我的假设:
我对此是否正确?
答案 1 :(得分:1)
好的,我将根据如何在laravel中设置表之间的关系来回答这个问题:
首先将 uid 更改为行程表SQL中的 user_id 。
在用户模型中,执行以下操作:
updatepanel
在旅行模型中:
// User created reviews
public function created_reviews()
{
return $this->hasMany(App\Review::class, 'reviewer_id');
}
// Reviews on User
public function reviews()
{
return $this->hasMany(App\Review::class, 'user_id');
}
// Organized Trips
public function trips()
{
return $this->hasMany(App\Trip::class);
}
在评论模型中:
// Trip Organizer
public function organizer()
{
return $this->belongsTo(App\User::class);
}
// Trip Reviews
public function reviews()
{
return $this->hasMany(App\Review::class);
}
如果您运行以下代码:
// Review Creator
public function sender()
{
return $this->belongsTo(App\User::class,'reviewer_id');
}
// Review Receiver
public function receiver()
{
return $this->belongsTo(App\User::class,'user_id');
}
// Associated Trip
public function trip()
{
return $this->belongsTo(App\Trip::class);
}
它将为您提供以下内容:
希望这有帮助。