This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello, I'm still stuck with relationships. In tutorial 21 there is a nice example in the order model of how to use a default value for a field by defining it via fields.yaml
....
code@create:
label: Code
span: left
defaultFrom: setupCode
....
and a method in the models php file like
public function getSetupCodeAttribute()
{
return strtoupper(str_random(8));
}
But I'm stuck with the question how to pass a value from a field from calling this model in a relationship - lets say from customer as described in the tutorial. E.g. If my customer has a default discount rate I would like to pass this rate as (changable) default to the order and later to each order item as well.
Thanks for any hints!
Hi!
You could try this...
code:
label: Code
span: left
defaultFrom: somerelation[setupCode]
Hello,
thanks for your reply but unfortunately this does not work as far as I can see. Tried it in different combinations, but got no default.
Found a very dirty workaround based on the url, but I'm not really happy with that :(
Given this problem, I would likely use a model accessor to access the related value: https://octobercms.com/docs/database/mutators#accessors-and-mutators
1-4 of 4