我正在尝试使用单个基类来抽象我的模型。我有三个继承自同一基础的模型:
我能够成功地将模型创建并保存到数据库,但是在获取时我得到一个空白屏幕,不会抛出任何错误。当我删除$with
属性时,一切似乎都有效。
下面是代码:
abstract class ItemType extends Model
{
public $timestamps = false;
protected $with = ['details'];
public function details()
{
return $this->morphOne(Item::class, 'type', 'item_details_type', 'item_details_id', 'id');
}
}
class Repair extends ItemType
{
protected $table = 'repairs';
protected $guarded = ['id', 'created_at', 'updated_at'];
protected $morphClass = self::class;
}
class Inspection extends ItemType {}
class Purchase extends ItemType {}
答案 0 :(得分:1)
最后,我决定使用if segue.identifier == "newRecord"
{
let controller = (segue.destinationViewController as! NewRecordVC)
let appDelegate = UIApplication.sharedApplication().delegate as? AppDelegate // instantiate the delegate methods in AppDelegate
controller.managedContext = appDelegate!.managedObjectContext // create context from delegate methods
let recordEntity = NSEntityDescription.entityForName("RecordData", inManagedObjectContext: controller.managedContext)
let locationEntity = NSEntityDescription.entityForName("Location", inManagedObjectContext: controller.managedContext)
controller.location = Location(entity: locationEntity!, insertIntoManagedObjectContext: controller.managedContext)
controller.record = Record(entity: recordEntity!, insertIntoManagedObjectContext: controller.managedContext)
print("segueing")
}
关系而不使用抽象类来解决问题。