Two tables serving as one model in Rails

Is it possible to install in rails on a model that depends on a join from two tables? This would mean that in order for the model record to be found / updated / destroyed, there must be both records in both database tables linked to each other in the join. The model will be just columns of both packed tables, which can then be used for forms, etc. So when a model is created / updated, is it just one hash of the form variable that applies to the model?

Is this possible in Rails 2 or 3?

+2
source share
3 answers

, Rails, , , , has_one :

class Widget < ActiveRecord::Base
  has_one :thingy
  before_save :save_thingy_object

  def save_thingy_object
    self.thingy = Thingy.new({ :attr1 => 'some', :attr2 => 'thing' })
  end
end

class Thingy < ActiveRecord::Base
  belongs_to :widget
end
0

Ruby on Rails . - , , , , .

0

All Articles