-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relationships defined in parent class + ignore abstract classes #11
Comments
I’m using PHPs reflection class to list the class methods. This should also return all inherited methods. |
I can check that later in the week. What I have tried before posting the issue: I copy/pasted the base method from the base class in the child classes. And that worked properly. |
Did you find some time to test this? |
Coming back from holiday. Will try to make a simple case to reproduce this before July end. |
I could reproduce this. When putting |
To reproduce that on a fresh install A migration to create the required tables public function up()
{
Schema::create('meetings', function (Blueprint $table) {
$table->increments('id');
$table->string('title')->nullable();
$table->timestamps();
});
Schema::create('participants', function (Blueprint $table) {
$table->increments('id');
$table->string('full_name')->nullable();
$table->unsignedInteger('meeting_id')->nullable();
$table->string('details_type')->nullable();
$table->unsignedInteger('details_id')->nullable();
$table->timestamps();
});
Schema::create('player_details', function (Blueprint $table) {
$table->increments('id');
$table->integer('skill_level')->nullable();
$table->timestamps();
});
Schema::create('referee_details', function (Blueprint $table) {
$table->increments('id');
$table->date('nominated_at')->nullable();
$table->timestamps();
});
} Corresponding model classesclass Meeting extends Model
{
public function participants(): HasMany
{
return $this->hasMany(Participant::class);
}
} class Participant extends Model
{
public function meeting(): BelongsTo
{
return $this->belongsTo(Meeting::class);
}
public function details(): MorphTo
{
return $this->morphTo('details');
}
} abstract class Details extends Model
{
public function participant(): MorphOne
{
return $this->morphOne(Participant::class, 'details');
}
} class PlayerDetails extends Details
{
} class RefereeDetails extends Details
{
} A test to check models are working as expected /** @test */
public function check_model_setup()
{
$meeting = Meeting::create();
$playerDetails = PlayerDetails::create();
$player = Participant::create();
$player->meeting()->associate($meeting)->save();
$player->details()->associate($playerDetails)->save();
$this->assertCount(1, Meeting::get());
$this->assertCount(1, PlayerDetails::get());
$this->assertCount(1, Participant::get());
$this->assertTrue($player->fresh()->details->is( PlayerDetails::first()));
} Diagram that gets generated |
Found the code responsible for this:
That means that all relationships defined in the base abstract get rejected because they are not directly attached to the current class. |
Removing that is not enough though. Something else is preventing the methods to get classified as relationships. On top of that method, I think you could safely exit when finding an abstract class. Or perhaps better, maybe you could represent the class inheritance on the diagram and keep the abstract class. |
Anybody find a work around here? |
Some of our models extend a common base class which defines a relationship for all of them.
These relationships are not taken into account in the graph.
For instance:
I think that any abstract class could be safely ignored.
And the inherited relationship should be pulled in each concrete class.
The text was updated successfully, but these errors were encountered: