Created
February 16, 2012 08:44
-
-
Save kagemusha/1843388 to your computer and use it in GitHub Desktop.
rails_admin with renamed model in belongs_to assoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tested on: Rails 3.2.1 | |
Will get error if don't add :foreign_key to has_many side of relat: | |
e.g. | |
class Song < ActiveRecord::Base | |
belongs_to :creator, :class_name=>"User" #person who added song entry | |
class User < ActiveRecord::Base | |
has_many :created_songs, :class_name=>"Song", :foreign_key => 'creator_id' | |
1. Here, User must have :foreign_key in its has_many statement | |
2. Make sure :class_name is a string! | |
:class_name=>:song will not work!! | |
https://github.com/sferik/rails_admin/blob/master/spec/dummy_app/app/models/league.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment