雄辩的5.7关系返回空

时间:2018-11-17 17:59:54

标签: php eloquent slim-3 eloquent--relationship

我现在被困住了,我测试了很多东西,看不到发生了什么,我需要创建一个预订摘要,但是我从关系中得到了空数据 我的表格是:
res_reservations键= idReservation
res_reservation_rooms键=保护程序

bouth表中的关系是idReservation

预订模型类

namespace Models\OBKE;
use Illuminate\Database\Eloquent\Model;
class Reservation extends Model{
      public $timestamps    = true;
      const CREATED_AT      = 'createdDate';
      const UPDATED_AT      = 'updatedDate';
      public $incrementing  = false;  
      protected $table      = "res_reservations";
      protected $primaryKey = "idReservation";
      protected $fillable = ["idReservation",
                             "resortName",
                             "programName",
                             "contract",
                             "lead",
                             "booker",
                             "total",
                             "idStatus",
                             "createdBy",
                             "updatedBy",
                             "currency",
                             "front",
                             "discount",
                             "pr_code"];

      public function rooms(){
        return $this->hasMany('\Models\OBKE\Reservation\Rooms',"idReservation","idReservation");
      }
 }

预订房间的型号课程

namespace Models\OBKE\Reservation;
use Illuminate\Database\Eloquent\Model;
class Rooms extends Model{

  public $timestamps = false;
  protected $table = "res_reservation_rooms";
  protected $primaryKey = "saver";
  protected $fillable=  [
    "idReservation",
    "row",
    "date",
    "idResort",
    "resortName",
    "idProgram",
    "programName",
    "idRoom",
    "roomName",
    "adults",
    "adultsRate",
    "juniors",
    "juniorsRate",
    "kids",
    "kidsRate",
    "infants",
    "infantsRate",
    "total",
    "discount"
  ];

  public function rooms(){
    return $this->belongsTo('\Models\OBKE\Reservation',"idReservation","idReservation");
  }
}

我尝试过与其他关系相同的调用,但仍然返回empty rooms array

我的问题是关于我做错了什么

1 个答案:

答案 0 :(得分:0)

这看起来令人困惑,我假设您有多个房间,每个房间都与多个预订相关联。

理想情况下,我们将有两个模型,

Models \ OBKE \ Rooms

methods

Models \ OBKE \ Reservation

scala> val f1 = A.doFirstThing _
// f1: () => Unit = $$Lambda$1317/1501701470@7306836f

scala> val f2 = A.doSecondThing _
// f2: () => Unit = $$Lambda$1318/545144829@2a3251ad

现在

  

Models \ OBKE \ Rooms :: get(1)为您提供单个房间对象

     

Models \ OBKE \ Rooms :: get(1)->预订,为您提供了一系列链接到房间的预订对象