Skip to content

Commit

Permalink
Merge pull request #1490 from bakaphp/refact-tags
Browse files Browse the repository at this point in the history
refact: remove apps and companies from morph table
  • Loading branch information
kaioken committed Jun 12, 2024
2 parents de46caa + 9e5b1ae commit 59a3ed8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/GraphQL/Social/Mutations/Tags/TagsManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function attachTagToEntity(mixed $root, array $request): bool

$tag->entities()->attach($entity->getId(), [
//'entity_namespace' => $systemModule->model_name,
'apps_id' => $tag->apps_id,
'companies_id' => $user->getCurrentCompany()->getId(),
//'apps_id' => $tag->apps_id,
//'companies_id' => $user->getCurrentCompany()->getId(),
'users_id' => $user->getId(),
'taggable_type' => $systemModule->model_name,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
*/
public function up(): void
{
//remove field entity_namespace from tags_entities
if (Schema::hasColumn('tags_entities', 'entity_namespace')) {
Schema::table('tags_entities', function (Blueprint $table) {
$table->dropColumn('entity_namespace');
});
}
Schema::table('tags_entities', function (Blueprint $table) {
$table->dropColumn('entity_namespace');
$table->dropColumn('apps_id');
$table->dropColumn('companies_id');
});
}

/**
Expand All @@ -25,6 +24,8 @@ public function down(): void
{
Schema::table('tags_entities', function (Blueprint $table) {
$table->string('entity_namespace', 255)->nullable();
$table->integer('apps_id')->nullable();
$table->integer('companies_id')->nullable();
});
}
};
12 changes: 2 additions & 10 deletions src/Domains/Social/Tags/Traits/HasTagsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@

trait HasTagsTrait
{
public function tags(bool $userCompany = true): MorphToMany
public function tags(): MorphToMany
{
$dbConnection = config('database.connections.social.database');

$query = $this->morphToMany(ModelsTag::class, 'taggable', $dbConnection . '.tags_entities', 'entity_id', 'tags_id')
->using(TagEntity::class)
->wherePivot('apps_id', $this->apps_id);


if ($userCompany) {
$query->wherePivot('companies_id', $this->companies_id);
}
->using(TagEntity::class);

return $query;
}
Expand All @@ -51,8 +45,6 @@ public function addTag(
))->execute();

$this->tags()->attach($this->getId(), [
'companies_id' => $company->getId(),
'apps_id' => $app->getId(),
'tags_id' => $tag->getId(),
'users_id' => $user->getId(),
'is_deleted' => 0,
Expand Down

0 comments on commit 59a3ed8

Please sign in to comment.