by Squeeeez · 1y ago · 0 comments
Like defining relationships between the models, on one side you define "representatives" - the other side then magically gets a "representative_id"? Why remove the s, why change abstraction between an object and its id?
Why does the framework manage to add a return reference there, but in other places like between domains and resources you need to add the back reference by hand?
But in general, love the concepts and clearly a lot of work went into it.
When you define a relationship like `has_many :representatives`, Ash does’t create `representative_id` on the destination resource, we only validate that it exists and meets some criteria.
No resource ever modifies another resource, so you have to define the id on the other side using `belongs_to` which modifies it's own resource only adding the `respresentative_id` attribute with this
`belongs_to :representative, Representative`
If you need custom field names, you can override them:
`has_many :representatives, MyApp.Representative, destination_attribute: :custom_reference_id`
The docs explain more: