src code

class method ActiveRecord.Model.hasOne

ActiveRecord.Model.hasOne(related_model_name[,options]) → null

Sepcifies a 1->1 relationship between models. The foreign key will reside in the related object. - related_model_name (String): Can be a plural or singular referring to the related table, the model name, or a reference to the model itself ("users","User" or User would all work). - options (Object)

Options can contain:

  • foreignKey (String)
  • name (String)
  • dependent (Boolean)
User.hasOne(CreditCard);
var u = User.find(5);
//each User instance will gain the following 3 methods
u.getCreditCard()
u.buildCreditCard()
u.createCreditCard()