statamic-rad-pack / runway

Eloquently manage your database models in Statamic.
https://statamic.com/addons/rad-pack/runway
MIT License
113 stars 49 forks source link

Relationship not augmenting #606

Closed vJoeyz closed 1 month ago

vJoeyz commented 1 month ago

Description

When trying to access relationships in the frontend, I only get the raw field (eg genus_id) and not the actual relationship objects. In the control panel everything works fine and the entries are linked properly. I've also tried adding 'with' => ['genus'] but that didn't help.

Steps to reproduce

  1. Create models:

    
    class Plant extends Model
    {
    use HasFactory, HasRunwayResource;
    
    protected $guarded = [];
    
    public $incrementing = false;
    
    public function genus(): BelongsTo
    {
        return $this->belongsTo(Genus::class);
    }
    }

class Genus extends Model { use HasFactory, HasRunwayResource;

protected $guarded = [];

public $incrementing = false;

public function plants(): HasMany
{
    return $this->hasMany(Plant::class);
}

}

2. Add to blueprint:

`plant.yaml`
```yaml
          -
            handle: genus_id
            field:
              resource: genus
              create: false
              type: belongs_to
              display: Genus
              localizable: false
              validate:
                - required

genus.yaml

          - handle: plants
            field:
              type: has_many
              display: Plants
              resource: plant
  1. Add to a (blade) template:
    <x-layout :context="$__data">
    @php(dd($__data))
    </x-layout>
  2. Only raw values are displayed, as in the foreign key but not the actual relationship
    array:65 [▼ // resources/views/plants/show.blade.php
    Variables {#2835 ▶}
    "id" => 16584
    "slug" => "rodgersia-hercules-rodher"
    "code" => "RODHER"
    ...
    "genus_id" => 15950
    "created_at" => "2024-09-20T12:20:05.000000Z"
    "updated_at" => "2024-09-20T12:20:05.000000Z"

Environment

Environment Application Name: Test Laravel Version: 11.23.5 PHP Version: 8.3.10 Composer Version: 2.7.7 Environment: local Debug Mode: ENABLED URL: hello.test Maintenance Mode: OFF Timezone: UTC Locale: en

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: log Cache: file Database: mysql Logs: stack / single Mail: log Queue: sync Session: file

Livewire Livewire: v3.5.6

Statamic Addons: 1 Sites: 3 (Nederlands, Deutsch, English) Stache Watcher: Enabled Static Caching: Disabled Version: 5.25.0 PRO

Statamic Addons statamic-rad-pack/runway: 7.9.3

duncanmcclean commented 1 month ago

Released as part of v7.9.5.