forked from kot-begemot/association_as_name
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
29 lines (22 loc) · 755 Bytes
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Structure:
class UserProfile < ActiveRecord::Base
belongs_to :home_country, :class_name => 'Country'
belongs_to :current_university, :class_name => 'University'
acts_as_aan do
association :current_university do
[:name]
end
association :home_country do
[:name, { :iso_3166_a2 => :country_code}]
end
end
validates :home_country, :presence => true
validates :current_university, :presence => true
end
Usage:
u = UserProfile.new
u.home_country_name = 'Netherlands'
u.current_university_name = 'University Of Amsterdam'
u.save # => true
u.home_country # => #<Country id: 12, name: "Netherlands"
u.home_country_name # => "Netherlands"