Relation fields need to accept procs for building relation query


(Aaron Russell) #1

Relation fields need another rethink as not all use cases are covered.

I envisage a use like this:

field :foo, :relation, to: -> { Article.published.other_scope.order(bar: :desc) }

This is probably quite easily achieved using the #relation_root method (which should possibly be renamed #relation):

def relation
  if @opts[:to].respond_to?(:call)
    model.instance_eval(&@opts[:to])
  else
    relation_class
  end
end

And then taxonomy and node fields will need reviewing too.


PushType development roadmap
(Aaron Russell) #2

Some more thoughts on this:

The ordering on a relationship query when the multiple option is set to true can be unpredictable. Really it should order by the order of the stored ids (unless a custom order is sent through the proc?).

More I think about it, need to start again with this one. Get rid of both the node and taxonomy fields and replace with one single relationship field.


(Aaron Russell) #3

Fixed with this commit:


(Aaron Russell) #4