- change relation between document and dataset_subjects to M : n:
a. during creating a dataste, also find existing keywords and attach them b. DatasetExtension.php c. Subject.php: protected $table = 'dataset_subjects'; d. migration file for crete_dataset_subjects_table - change api routes for also using url alias if defined - composer updates: composer.lock
This commit is contained in:
parent
105e31dbbd
commit
75b37368e4
7 changed files with 115 additions and 34 deletions
|
@ -479,8 +479,13 @@ class IndexController extends Controller
|
|||
//save keywords
|
||||
if (isset($data['keywords'])) {
|
||||
foreach ($request->get('keywords') as $key => $keyword) {
|
||||
$dataKeyword = new Subject($keyword);
|
||||
$dataset->subjects()->save($dataKeyword);
|
||||
// $dataKeyword = new Subject($keyword);
|
||||
// $dataset->subjects()->save($dataKeyword);
|
||||
$keyword = Subject::firstOrCreate(
|
||||
['value' => $keyword['value']],
|
||||
$keyword
|
||||
);
|
||||
$dataset->subjects()->attach($keyword);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ trait DatasetExtension
|
|||
),
|
||||
'Subject' => array(
|
||||
'model' => Subject::class,
|
||||
'through' => 'link_dataset_subjects',
|
||||
'relation' => 'subjects',
|
||||
'fetch' => 'eager'
|
||||
),
|
||||
|
|
|
@ -260,9 +260,13 @@ class Dataset extends Model
|
|||
return $this->hasMany(\App\Models\DatasetReference::class, 'document_id', 'id');
|
||||
}
|
||||
|
||||
// public function subjects()
|
||||
// {
|
||||
// return $this->hasMany(\App\Models\Subject::class, 'document_id', 'id');
|
||||
// }
|
||||
public function subjects()
|
||||
{
|
||||
return $this->hasMany(\App\Models\Subject::class, 'document_id', 'id');
|
||||
return $this->belongsToMany(\App\Models\Subject::class, 'link_dataset_subjects', 'document_id', 'subject_id');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,13 +7,18 @@ use App\Models\Dataset;
|
|||
|
||||
class Subject extends Model
|
||||
{
|
||||
protected $table = 'document_subjects';
|
||||
// protected $table = 'document_subjects';
|
||||
protected $table = 'dataset_subjects';
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['value', 'type', 'language'];
|
||||
|
||||
public function dataset()
|
||||
// public function dataset()
|
||||
// {
|
||||
// return $this->belongsTo(Dataset::class, 'document_id', 'id');
|
||||
// }
|
||||
public function datasets()
|
||||
{
|
||||
return $this->belongsTo(Dataset::class, 'document_id', 'id');
|
||||
return $this->belongsToMany(Dataset::class, 'link_dataset_subjects', 'subject_id', 'document_id');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue