administrate
administrate copied to clipboard
How could I make a delegated object behave like a belongs_to?
I'm delegating my user on one of my dashboard models:
delegate :user, to: :property
The model belongs to the property so I want to be able to display that delegated user as a regular Field::BelongsTo is there a way to achieve this?
Have you found a solution?
Would it be possible to use has_one+through instead of delegate? Something like this:
class MyModel < ApplicationRecord
belongs_to :property
has_one :user, through: :property
end
I tried this in the example app and it worked. I could add user as a BelongsTo field to my dashboard.
Using the has_one through just worked for me in this scenario. Although I'm a little concerned about changes to the performance of other unrelated code in the codebase that was using the delegate method and is now using the has_one through method.