--- !ruby/object:RI::MethodDescription 
aliases: []

block_params: 
comment: 
- !ruby/struct:SM::Flow::P 
  body: "Adds the following methods for retrieval and query of a single associated object: <tt>association</tt> is replaced with the symbol passed as the first argument, so <tt>has_one :manager</tt> would add among others <tt>manager.nil?</tt>."
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>association(force_reload = false)</tt> - Returns the associated object. <tt>nil</tt> is returned if none is found.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>association=(associate)</tt> - Assigns the associate object, extracts the primary key, sets it as the foreign key, and saves the associate object.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>association.nil?</tt> - Returns <tt>true</tt> if there is no associated object.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "<tt>build_association(attributes = {})</tt> - Returns a new object of the associated type that has been instantiated with <tt>attributes</tt> and linked to this object through a foreign key, but has not yet been saved. Note: This ONLY works if an association already exists. It will NOT work if the association is <tt>nil</tt>."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>create_association(attributes = {})</tt> - Returns a new object of the associated type that has been instantiated with <tt>attributes</tt>, linked to this object through a foreign key, and that has already been saved (if it passed the validation).
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "Example: An Account class declares <tt>has_one :beneficiary</tt>, which will add:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "<tt>Account#beneficiary</tt> (similar to <tt>Beneficiary.find(:first, :conditions =&gt; &quot;account_id = #{id}&quot;)</tt>)"
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>Account#beneficiary=(beneficiary)</tt> (similar to <tt>beneficiary.account_id = account.id; beneficiary.save</tt>)
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>Account#beneficiary.nil?</tt>
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>Account#build_beneficiary</tt> (similar to <tt>Beneficiary.new(&quot;account_id&quot; =&gt; id)</tt>)
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>Account#create_beneficiary</tt> (similar to <tt>b = Beneficiary.new(&quot;account_id&quot; =&gt; id); b.save; b</tt>)
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: The declaration can also include an options hash to specialize the behavior of the association.
- !ruby/struct:SM::Flow::P 
  body: "Options are:"
- !ruby/object:SM::Flow::LIST 
  contents: 
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:class_name</tt> - Specify the class name of the association. Use it only if that name can't be inferred from the association name. So <tt>has_one :manager</tt> will by default be linked to the Manager class, but if the real class name is Person, you'll have to specify it with this option.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:conditions</tt> - Specify the conditions that the associated object must meet in order to be included as a <tt>WHERE</tt> SQL fragment, such as <tt>rank = 5</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:order</tt> - Specify the order in which the associated objects are returned as an <tt>ORDER BY</tt> SQL fragment, such as <tt>last_name, first_name DESC</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:dependent</tt> - If set to <tt>:destroy</tt>, the associated object is destroyed when this object is. If set to <tt>:delete</tt>, the associated object is deleted <b>without</b> calling its destroy method. If set to <tt>:nullify</tt>, the associated object's foreign key is set to <tt>NULL</tt>. Also, association is assigned.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:foreign_key</tt> - Specify the foreign key used for the association. By default this is guessed to be the name of this class in lower-case and &quot;_id&quot; suffixed. So a Person class that makes a <tt>has_one</tt> association will use &quot;person_id&quot; as the default <tt>:foreign_key</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:include</tt> - Specify second-order associations that should be eager loaded when this object is loaded.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:as</tt> - Specifies a polymorphic interface (See <tt>belongs_to</tt>).
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:select</tt> - By default, this is <tt>*</tt> as in <tt>SELECT * FROM</tt>, but can be changed if, for example, you want to do a join but not include the joined columns. Do not forget to include the primary and foreign keys, otherwise it will raise an error.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: "<tt>:through</tt>: Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt> and <tt>:foreign_key</tt> are ignored, as the association uses the source reflection. You can only use a <tt>:through</tt> query through a <tt>has_one</tt> or <tt>belongs_to</tt> association on the join model."
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:source</tt> - Specifies the source association name used by <tt>has_one :through</tt> queries. Only use it if the name cannot be inferred from the association. <tt>has_one :favorite, :through =&gt; :favorites</tt> will look for a <tt>:favorite</tt> on Favorite, unless a <tt>:source</tt> is given.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:source_type</tt> - Specifies type of the source association used by <tt>has_one :through</tt> queries where the source association is a polymorphic <tt>belongs_to</tt>.
  - !ruby/struct:SM::Flow::LI 
    label: "*"
    body: <tt>:readonly</tt> - If true, the associated object is readonly through the association.
  type: :BULLET
- !ruby/struct:SM::Flow::P 
  body: "Option examples:"
- !ruby/struct:SM::Flow::VERB 
  body: "  has_one :credit_card, :dependent =&gt; :destroy  # destroys the associated credit card\n  has_one :credit_card, :dependent =&gt; :nullify  # updates the associated records foreign key value to NULL rather than destroying it\n  has_one :last_comment, :class_name =&gt; &quot;Comment&quot;, :order =&gt; &quot;posted_on&quot;\n  has_one :project_manager, :class_name =&gt; &quot;Person&quot;, :conditions =&gt; &quot;role = 'project_manager'&quot;\n  has_one :attachment, :as =&gt; :attachable\n  has_one :boss, :readonly =&gt; :true\n  has_one :club, :through =&gt; :membership\n  has_one :primary_address, :through =&gt; :addressables, :conditions =&gt; [&quot;addressable.primary = ?&quot;, true], :source =&gt; :addressable\n"
full_name: ActiveRecord::Associations::ClassMethods#has_one
is_singleton: false
name: has_one
params: (association_id, options = {})
visibility: public
