Skip to content

Conversation

@eucyt
Copy link
Contributor

@eucyt eucyt commented Oct 29, 2025

Resolve #733

Changes

Currently, when creating a polymorphic model, you have to set the discriminator value manually each time, even though the value is obvious.

$message = (new TextMessage())
  ->setType(\LINE\Constants\MessageType::TEXT) // this is redundant.
  ->setText('hello!');

With this implementation, the discriminator value will be automatically set in the constructor.

$message = (new TextMessage())
  ->setText('hello!');

$this->assertEquals('text', $message->getType()); // Passed

For reviewers

Since this commit contains many auto-generated files, I recommend reviewing it.

Add tests
Fix template

@eucyt eucyt requested a review from a team October 29, 2025 09:14
@eucyt eucyt self-assigned this Oct 29, 2025
Copy link
Contributor

@habara-k habara-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@eucyt eucyt added this pull request to the merge queue Oct 31, 2025
Merged via the queue into line:master with commit 96e06a1 Oct 31, 2025
7 checks passed
@eucyt eucyt deleted the feature/auto-set-discriminator branch October 31, 2025 05:52
github-merge-queue bot pushed a commit that referenced this pull request Nov 6, 2025
…iscriminator value automatically (#755)

Update documents and examples related to
#752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make it unnecessary to manually set the type in the Message model.

2 participants