- 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
|
@ -479,8 +479,13 @@ class IndexController extends Controller
|
||||||
//save keywords
|
//save keywords
|
||||||
if (isset($data['keywords'])) {
|
if (isset($data['keywords'])) {
|
||||||
foreach ($request->get('keywords') as $key => $keyword) {
|
foreach ($request->get('keywords') as $key => $keyword) {
|
||||||
$dataKeyword = new Subject($keyword);
|
// $dataKeyword = new Subject($keyword);
|
||||||
$dataset->subjects()->save($dataKeyword);
|
// $dataset->subjects()->save($dataKeyword);
|
||||||
|
$keyword = Subject::firstOrCreate(
|
||||||
|
['value' => $keyword['value']],
|
||||||
|
$keyword
|
||||||
|
);
|
||||||
|
$dataset->subjects()->attach($keyword);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ trait DatasetExtension
|
||||||
),
|
),
|
||||||
'Subject' => array(
|
'Subject' => array(
|
||||||
'model' => Subject::class,
|
'model' => Subject::class,
|
||||||
|
'through' => 'link_dataset_subjects',
|
||||||
'relation' => 'subjects',
|
'relation' => 'subjects',
|
||||||
'fetch' => 'eager'
|
'fetch' => 'eager'
|
||||||
),
|
),
|
||||||
|
|
|
@ -260,9 +260,13 @@ class Dataset extends Model
|
||||||
return $this->hasMany(\App\Models\DatasetReference::class, 'document_id', 'id');
|
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()
|
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
|
class Subject extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'document_subjects';
|
// protected $table = 'document_subjects';
|
||||||
|
protected $table = 'dataset_subjects';
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
protected $fillable = ['value', 'type', 'language'];
|
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
52
composer.lock
generated
52
composer.lock
generated
|
@ -3870,16 +3870,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/http-foundation",
|
"name": "symfony/http-foundation",
|
||||||
"version": "v5.3.0",
|
"version": "v5.3.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/http-foundation.git",
|
"url": "https://github.com/symfony/http-foundation.git",
|
||||||
"reference": "31f25d99b329a1461f42bcef8505b54926a30be6"
|
"reference": "8827b90cf8806e467124ad476acd15216c2fceb6"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/31f25d99b329a1461f42bcef8505b54926a30be6",
|
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/8827b90cf8806e467124ad476acd15216c2fceb6",
|
||||||
"reference": "31f25d99b329a1461f42bcef8505b54926a30be6",
|
"reference": "8827b90cf8806e467124ad476acd15216c2fceb6",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -3923,7 +3923,7 @@
|
||||||
"description": "Defines an object-oriented layer for the HTTP specification",
|
"description": "Defines an object-oriented layer for the HTTP specification",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/http-foundation/tree/v5.3.0"
|
"source": "https://github.com/symfony/http-foundation/tree/v5.3.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -3939,20 +3939,20 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-05-26T17:43:10+00:00"
|
"time": "2021-06-02T09:32:00+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/http-kernel",
|
"name": "symfony/http-kernel",
|
||||||
"version": "v5.3.0",
|
"version": "v5.3.1",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/http-kernel.git",
|
"url": "https://github.com/symfony/http-kernel.git",
|
||||||
"reference": "f8e8f5391b6909e2f0ba8c12220ab7af3050eb4f"
|
"reference": "74eb022e3bac36b3d3a897951a98759f2b32b864"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/f8e8f5391b6909e2f0ba8c12220ab7af3050eb4f",
|
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/74eb022e3bac36b3d3a897951a98759f2b32b864",
|
||||||
"reference": "f8e8f5391b6909e2f0ba8c12220ab7af3050eb4f",
|
"reference": "74eb022e3bac36b3d3a897951a98759f2b32b864",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -4035,7 +4035,7 @@
|
||||||
"description": "Provides a structured process for converting a Request into a Response",
|
"description": "Provides a structured process for converting a Request into a Response",
|
||||||
"homepage": "https://symfony.com",
|
"homepage": "https://symfony.com",
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://github.com/symfony/http-kernel/tree/v5.3.0"
|
"source": "https://github.com/symfony/http-kernel/tree/v5.3.1"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -4051,7 +4051,7 @@
|
||||||
"type": "tidelift"
|
"type": "tidelift"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-05-31T10:44:03+00:00"
|
"time": "2021-06-02T10:07:12+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/mime",
|
"name": "symfony/mime",
|
||||||
|
@ -6515,16 +6515,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/phpunit",
|
"name": "phpunit/phpunit",
|
||||||
"version": "9.5.4",
|
"version": "9.5.5",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||||
"reference": "c73c6737305e779771147af66c96ca6a7ed8a741"
|
"reference": "89ff45ea9d70e35522fb6654a2ebc221158de276"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c73c6737305e779771147af66c96ca6a7ed8a741",
|
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/89ff45ea9d70e35522fb6654a2ebc221158de276",
|
||||||
"reference": "c73c6737305e779771147af66c96ca6a7ed8a741",
|
"reference": "89ff45ea9d70e35522fb6654a2ebc221158de276",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -6554,7 +6554,7 @@
|
||||||
"sebastian/global-state": "^5.0.1",
|
"sebastian/global-state": "^5.0.1",
|
||||||
"sebastian/object-enumerator": "^4.0.3",
|
"sebastian/object-enumerator": "^4.0.3",
|
||||||
"sebastian/resource-operations": "^3.0.3",
|
"sebastian/resource-operations": "^3.0.3",
|
||||||
"sebastian/type": "^2.3",
|
"sebastian/type": "^2.3.2",
|
||||||
"sebastian/version": "^3.0.2"
|
"sebastian/version": "^3.0.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
@ -6602,7 +6602,7 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.4"
|
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.5"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -6614,7 +6614,7 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2021-03-23T07:16:29+00:00"
|
"time": "2021-06-05T04:49:07+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/cli-parser",
|
"name": "sebastian/cli-parser",
|
||||||
|
@ -7473,16 +7473,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/type",
|
"name": "sebastian/type",
|
||||||
"version": "2.3.1",
|
"version": "2.3.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/type.git",
|
"url": "https://github.com/sebastianbergmann/type.git",
|
||||||
"reference": "81cd61ab7bbf2de744aba0ea61fae32f721df3d2"
|
"reference": "0d1c587401514d17e8f9258a27e23527cb1b06c1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/type/zipball/81cd61ab7bbf2de744aba0ea61fae32f721df3d2",
|
"url": "https://api.github.com/repos/sebastianbergmann/type/zipball/0d1c587401514d17e8f9258a27e23527cb1b06c1",
|
||||||
"reference": "81cd61ab7bbf2de744aba0ea61fae32f721df3d2",
|
"reference": "0d1c587401514d17e8f9258a27e23527cb1b06c1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -7517,7 +7517,7 @@
|
||||||
"homepage": "https://github.com/sebastianbergmann/type",
|
"homepage": "https://github.com/sebastianbergmann/type",
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/sebastianbergmann/type/issues",
|
"issues": "https://github.com/sebastianbergmann/type/issues",
|
||||||
"source": "https://github.com/sebastianbergmann/type/tree/2.3.1"
|
"source": "https://github.com/sebastianbergmann/type/tree/2.3.2"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -7525,7 +7525,7 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2020-10-26T13:18:59+00:00"
|
"time": "2021-06-04T13:02:07+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/version",
|
"name": "sebastian/version",
|
||||||
|
@ -7701,5 +7701,5 @@
|
||||||
"platform-overrides": {
|
"platform-overrides": {
|
||||||
"php": "7.3"
|
"php": "7.3"
|
||||||
},
|
},
|
||||||
"plugin-api-version": "2.0.0"
|
"plugin-api-version": "2.1.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateDatasetSubjects extends Migration
|
||||||
|
{
|
||||||
|
// php artisan make:migration create_dataset_subjects_table --table=dataset_subjects --create=dataset_subjects
|
||||||
|
// php artisan migrate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('dataset_subjects', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('language', 3)->nullable();
|
||||||
|
$table->enum(
|
||||||
|
'type',
|
||||||
|
['uncontrolled']
|
||||||
|
);
|
||||||
|
$table->string('value', 255);
|
||||||
|
$table->string('external_key', 255)->nullable();
|
||||||
|
$table->nullableTimestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::create('link_dataset_subjects', function (Blueprint $table) {
|
||||||
|
// $table->increments('id');
|
||||||
|
|
||||||
|
$table->unsignedInteger('subject_id')->index();
|
||||||
|
$table->foreign('subject_id')
|
||||||
|
->references('id')->on('dataset_subjects')
|
||||||
|
->onDelete('no action')->onUpdate('no action'); //detach the relation via code
|
||||||
|
|
||||||
|
$table->unsignedInteger('document_id')->index();
|
||||||
|
$table->foreign('document_id')
|
||||||
|
->references('id')->on('documents')
|
||||||
|
->onDelete('cascade')->onUpdate('cascade');
|
||||||
|
|
||||||
|
$table->primary(['subject_id', 'document_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('link_dataset_subjects');
|
||||||
|
Schema::dropIfExists('dataset_subjects');
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,8 +14,11 @@ use App\Models\Person;
|
||||||
| is assigned the "api" middleware group. Enjoy building your API!
|
| is assigned the "api" middleware group. Enjoy building your API!
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
$base_domain = config('app.url');
|
||||||
|
$alias_domain = config('app.alias_url');
|
||||||
|
|
||||||
Route::domain('tethys.at')->group(function () {
|
// Route::domain('tethys.at')->group(function () {
|
||||||
|
$appRoutes = function () {
|
||||||
|
|
||||||
Route::match(array('GET', 'POST'), '/oai', ['as' => 'oai', 'uses' => 'Oai\RequestController@index']);
|
Route::match(array('GET', 'POST'), '/oai', ['as' => 'oai', 'uses' => 'Oai\RequestController@index']);
|
||||||
|
|
||||||
|
@ -79,4 +82,9 @@ Route::domain('tethys.at')->group(function () {
|
||||||
->header('Access-Control-Allow-Origin', '*')
|
->header('Access-Control-Allow-Origin', '*')
|
||||||
->header('Access-Control-Allow-Methods', 'GET');
|
->header('Access-Control-Allow-Methods', 'GET');
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
|
Route::group(array('domain' => $base_domain), $appRoutes);
|
||||||
|
if ($alias_domain) {
|
||||||
|
Route::group(array('domain' => $alias_domain), $appRoutes);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user