Skip to content
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

Inconsistent attribute naming of eagerly loaded polymorphic relation #9427

Closed
jarnovanleeuwen opened this issue Jun 26, 2015 · 2 comments
Closed

Comments

@jarnovanleeuwen
Copy link
Contributor

Hello,

The attribute names of eagerly loaded polymorphic relationships are using snake casing, while other relationships (e.g., BelongsTo) are named in camel casing fashion. Example:

class Payment extends Model
{
    public function paymentProfile()
    {
        return $this->belongsTo(PaymentProfile::class);
    }

    public function paymentDetails()
    {
        return $this->morphTo();
    }
}

Behaviour:

$payment = Payment::with('paymentProfile', 'paymentDetails')->first();

var_dump($payment->paymentProfile); // PaymentProfile instance

var_dump($payment->paymentDetails); // NULL

var_dump($payment->payment_details); // SepaDirectDebitPaymentDetails instance

If I remember correctly, it should be independent of the relation type used and should follow the method's name (PaymentDetails in this case).

Jarno

@GrahamCampbell
Copy link
Member

You need to call:

var_dump($payment->payment_profile);

@jarnovanleeuwen
Copy link
Contributor Author

Fixed in #15334.

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

No branches or pull requests

2 participants