F
Filament14mo ago
Connor

Relation Manager Not Showing related items

//CheckoutSession.php
public function checkoutItems(){
return $this->hasMany(CheckoutItem::class, 'stripe_checkout_id');
}

//CheckoutItem.php
public function checkoutSession()
{
return $this->belongsTo(CheckoutSession::class, 'stripe_checkout_id');
}
//CheckoutSession.php
public function checkoutItems(){
return $this->hasMany(CheckoutItem::class, 'stripe_checkout_id');
}

//CheckoutItem.php
public function checkoutSession()
{
return $this->belongsTo(CheckoutSession::class, 'stripe_checkout_id');
}
The section appears at the bottom of my edit CheckoutSession, It just doesnt display any results, however I can see the entries in the DB and the relationships are defined
No description
No description
No description
Solution:
Looks like you have an 'id' field on your stripe_checkout_items table, which is presumably set to be the Primary Key in the migration? In which case the stripe_checkout_id you are trying to use as the FK in the relationship would be expected to reference the 'id' PK on the parent. So again, you probably need to modify your relationship methods on the model to specify the "owner key" as well as the foreign key.
Jump to solution
2 Replies
Solution
cheesegrits
cheesegrits14mo ago
Looks like you have an 'id' field on your stripe_checkout_items table, which is presumably set to be the Primary Key in the migration? In which case the stripe_checkout_id you are trying to use as the FK in the relationship would be expected to reference the 'id' PK on the parent. So again, you probably need to modify your relationship methods on the model to specify the "owner key" as well as the foreign key.
Connor
ConnorOP14mo ago
Right that makes sense to me somewhat, I'm just trying to figure out how I make this work, I've not really delved into relationship stuff too much yet. Managed to make it work! appreciate the help!
public function checkoutItems(){
return $this->hasMany(CheckoutItem::class, 'stripe_checkout_id', 'stripe_checkout_id');
}
public function checkoutItems(){
return $this->hasMany(CheckoutItem::class, 'stripe_checkout_id', 'stripe_checkout_id');
}
Want results from more Discord servers?
Add your server