class Todo < DataMapper::Base property :todo, :text property :status, :string property :done, :boolean belongs_to :context belongs_to :category def to_s "#{status} #{todo} <#{context}> [#{category}] -- #{done.to_s}" end end Todo.table.create! unless Todo.table.exists? class Category < DataMapper::Base property :name, :string has_many :todos end Category.table.create! unless Category.table.exists? class Context < DataMapper::Base property :name, :string has_many :todos end # je crée mon model comme ceci: (todo est un hash que j'obtiens par une methode que je n'ai pas indiquer ici) t = Todo.new({:status => todo[:status], :todo => todo[:todo], :done => false}) context = t.context.create :name => todo[:context] category = t.category.create :name => todo[:category] t.save