0

I have created the front end relationship between my models image and album by using hasMany and belongsTo however I am not getting any results displayed and {{ dump(images) }} and {{ dump(albums) }} gives Object variables NULL 0 NULL

Any Ideas why the relationship is not being picked up?

Album

public $hasMany = [
'images' => [ 'Acme\Library\Models\Image' ,'key'=>'album_id'],
];

Image

public $belongsTo = [
'albums' => ['Acme\Library\Models\Album']
];

album-details.htm

{{ dump(images) }}
{% for image in images %}
{{image.id|raw }}
{% endfor %}

if I run a dump on {{ dump(record) }} I get

Object variables
Acme\Library\Models\Album
bootValidation()    method  Boot the validation trait for this model. 
forceSave() method  Force save the model even if validation fails.
validate()  method  Validate the model instance
isAttributeRequired()  method  Determines if an attribute is required based      on the validation rules.
errors()    method  Get validation error message collection for the Model
validating()    method  Create a new native event for handling    beforeValidate().
validated() method  Create a new native event for handling afterValidate().
rules   array(0)    
timestamps  boolean 
table   string  
relationConfig  string  
hasMany array(1)

I can see using the builder plugin that record is defined {% set records = builderList.records %}

Does albums/images need to be defined in this manner also?

tom harrison
  • 3,273
  • 11
  • 42
  • 71

1 Answers1

1

I you send record variable to the view and record is an instance of Album you can access your images this way.

{% for image in record.images %}
  {{image.id|raw }}
{% endfor %}
KerooZ
  • 61
  • 6