public class Miner ...{
// Other fields/methods omitted
![]()
private GoldClaim goldClaim;
/**//**
* @hibernate.many-to-one column="gold_claim_id"
* cascade="save"
*/
public GoldClaim getGoldClaim() ...{ return goldClaim; }
public void setGoldClaim(GoldClaim goldClaim) ...{
this.goldClaim = goldClaim;
}
}
![]()
(Rails)
class Miner < ActiveRecord::Base
belongs_to :gold_claim
end
miner = Miner.new("name" => "Brom Garrott")
miner.gold_claim = GoldClaim.new( "name" => "Western Slope")
miner.save # This saves both the Miner and GoldClaim objects
miner.destroy # Deletes only the miner row from the database
Miner miner = new Miner();
miner.setGoldClaim(new GoldClaim());
session.save(miner); // Saves Miner and GoldClaim objects.
session.delete(miner); // Deletes both of them.
miner = Miner.find(@params['id'])
miner.gold_claim.name = "Eastern Slope"
miner.save
class GoldClaim < ActiveRecord::Base
has_one :miner
end
![]()
claim = GoldClaim.find(@params['id'])
claim.miner.name = "Seth Bullock"
claim.save # Saves the miner's name