How to use custom read action with arguments as has_many read_action?

I have this read action in my resource A:

read :by_entity do
      argument :entity_full_name, :string, allow_nil?: false

      filter expr(
               fragment("(? %> ?)", first_grantee_full_name, ^arg(:entity_full_name)) and
                 not is_nil(recording_date || instrument_date) and
                 (recording_date || instrument_date) >= ago(2, :year) and
                 not deleted?
             )

      prepare build(sort: [:recording_date], load: [:sell_record, :fix_and_flip?])
    end

resource B has an attribute called :entity_name, I want to join resource A to a resource B using that read action, AFAIK, to do that I would need to do this:

    has_many :owner_records, Record do
      no_attributes? true

      read_action :by_entity
    end

The problem is that I don’t know how to pass resource B :entity_name attribute as the argument for resource A read action :by_entity argument :entity_full_name in the has_many code block.

Is that possible? How can I achieve that?

There is no good way to do that. What you will likely need to do is implement a manual relationship.

I was able to achieve something similar to this by changing the read action to this:

    read :valid do
      filter expr(
                 not is_nil(recording_date || instrument_date) and
                 (recording_date || instrument_date) >= ago(2, :year) and
                 not deleted?
             )

      prepare build(sort: [:recording_date], load: [:sell_record, :fix_and_flip?])
    end

And changing the relationship to this:

    has_many :owner_records, Record do
      no_attributes? true

      read_action :valid

      filter expr(
            fragment("(? %> ?)", first_grantee_full_name, parent(first_owner[:full_name]))
            )
    end