Aliased foreign_key

35 views
Skip to first unread message

Hugo Tunius

unread,
May 29, 2015, 1:47:51 PM5/29/15
to rubyonra...@googlegroups.com
Hey everyone,

I am working on a project which among other things involves a legacy database schema that does not follow rails conventions. In an attempt to try and hide this fact I've taken to aliasing all attributes to what they would have been called if built in Rails from the beginning. One place where this doesn't work however is for foreign keys in associations. My longterm goal is being abel to change the database schema and only removing the aliases.

As an example

class Post < ActiveRecord::Base
 
alias_attribute :user_id :userId
 
 
# For the foreign_key it's not possible to use the aliased value `user_id`
  belongs_to
:user, foreign_key: :userId
end

Is this a deliberate decision or just something that has happend naturally and never been brought up? If it's something that you would be willing to accept a PR for I would love to give it a shot.


Regards
Hugo

Reply all
Reply to author
Forward
0 new messages