On 28 August 2010 17:01, dev2 <[email protected]> wrote:
> When I automigrate these models I don't get the results I expect.
> After migrating the person table now has included the fields from the
> doctor table which seems incorrect to me as most of the entries in the
> person table won't have 'doctor' properties.   My purpose of using STI
> is to make it easier to create/update a doctor person.   The way I do
> it now I save the person data and if that succeeds then I create an
> entry in the doctor table with the corresponding person_id.   Any
> help?

STI is Single Table Inheritance.  Note the single in the name :)

For the data layout you want, you could have the Doctor model belong_to
:person.  (which actually, looking at it, you have the property there
already).  For saving models, if you wrap in a transaction, that should solve
potential for inconsistency issues.

require 'dm-transactions'

Person.transaction do
  if @person.save
    @doctor = Doctor.new
    @doctor.person = @person
    unless @doctor.save
      raise "Transaction failed" # rollback transaction
    end
  else
    raise "Transaction failed" # rollback transaction
  end
end

Regards
Jon

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" 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 this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to