Skip to content

Commit

Permalink
Merge pull request #28 from Josje92/fix/prevent-duplicate-identifiers
Browse files Browse the repository at this point in the history
fix(model-generator): prevent duplicate identifier issues
  • Loading branch information
lepikhinb committed Jul 15, 2023
2 parents accfcd5 + b8651e5 commit 33aef8b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Generators/ModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ protected function getProperties(): string

protected function getAccessors(): string
{
$relationsToSkip = $this->getRelationMethods()
->map(function (ReflectionMethod $method) {
return Str::snake($method->getName());
});

return $this->getMethods()
->filter(fn (ReflectionMethod $method) => Str::startsWith($method->getName(), 'get'))
->filter(fn (ReflectionMethod $method) => Str::endsWith($method->getName(), 'Attribute'))
Expand All @@ -90,6 +95,9 @@ protected function getAccessors(): string
->reject(function (ReflectionMethod $method, string $property) {
return $this->columns->contains(fn (Column $column) => $column->getName() == $property);
})
->reject(function (ReflectionMethod $method, string $property) use ($relationsToSkip) {
return $relationsToSkip->contains($property);
})
->map(function (ReflectionMethod $method, string $property) {
return (string) new TypeScriptProperty(
name: $property,
Expand Down

0 comments on commit 33aef8b

Please sign in to comment.