Hi Fred,
I would argue against this. Here''s my understanding:
The table names are generated from the name-spaced class name to avoid
naming collisions. Meanwhile the current practice is to generate the
foreign_key column not from the target class, but from the association
name. This means we doesn''t risk naming collisions, as you would have
to
have 2 differently named associations to reference the 2 differently
name-spaced target objects.
Basically, it''s up to the author to name their associations, and in
doing
so select the names for their foreign key columns. That these most often
overlap with the model names is a convenient coincidence.
-Ben
On Mon, Jun 18, 2012 at 4:10 PM, Fred Wu <ifredwu@gmail.com> wrote:
> Hi,
>
> I''ve done a quick search and haven''t found any info on
this topic, my
> apologies if this has already been addressed before.
>
> Given the following two activerecord models:
>
> N::A and N::B
>
> module N
> class A
> has_one :b
> endend
> module N
> class B
> belongs_to :a
> endend
>
> Since the two models are in the same namespace, has_one and belongs_to (or
> any other association) work fine with simply :a and :b.
>
> However, the naming convention between the models and foreign keys is
> inconsistent.
>
> The ActiveRecord model tables, by default are:
>
> n_a for N::A
> n_b for N::B
>
> However, the foreign key for A::B is:
>
> a_id
>
> To keep things consistent, shouldn''t the default foreign key be
n_a_id
> instead?
>
> Issue on GitHub: https://github.com/rails/rails/issues/6731
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-core/-/-0Dlko6JY1QJ.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-core+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.