i have a user model with fields name and sex. And each user can have an
one-to-one association called "father" with a male user.

So in user model i added a field father_id and added association like
this,

class User < ActiveRecord::Base
  belongs_to :father, :class_name => 'User', :inverse_of => :user,
:foreign_key => "father_id"
  has_one :user, :class_name => 'User', :inverse_of => :father

  SEX=["male", "female"]

  validates :sex, :presence => true,:inclusion => { :in => SEX }

end

now it can make both female user and male user as father. How could i
restrict it to make user as father only whose sex is male?

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to