Was thinking of exploring a simple heuristic to avoid having to specify 
`inverse_of` and `foreign_key` as much.

When defining a `has_many` or `has_one` relationship and the relationship 
name doesn't match up with the model name we must specify `foreign_key`. In 
addition, if we want to avoid extra queries we must specify `inverse_of`. 
Take a typical tree model for example:

with_options class_name: name do
  belongs_to :parent, inverse_of: :children
  has_many :children, foreign_key: :parent_id, inverse_of: :parent
end

It seems if we have specified the `foreign_key` then perhaps it could guess 
the `inverse_of`. Or maybe turn it around. If `inverse_of` is specified 
then perhaps `foreign_key` can be guessed.

This would seem in line with the many existing heuristics that ActiveRecord 
already has to reduce the number of options that need to be specified. If 
there is interested in accepting a change such as this I would be happy to 
work on a PR.

Eric

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to