Created
September 16, 2010 07:04
-
-
Save WaYdotNET/582079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/bar.rb | |
class Bar | |
include DataMapper::Resource | |
# property <name>, <type> | |
property :id, Serial | |
property :name, String | |
# has many to many | |
has n, :foos, :through => Resource | |
end | |
# app/models/foo.rb | |
class Foo | |
include DataMapper::Resource | |
# property <name>, <type> | |
property :id, Serial | |
property :name, String | |
# has many to many | |
has n, :bars, :through => Resource | |
end | |
# app/app.rb | |
get :index do | |
# 1) create a first foo | |
Foo.create(:name => "foo1") | |
# create a three bar | |
(1..3).each {|i| Bar.create(:name => "bar_#{i}") } | |
# 2) get foo | |
foo = Foo.first | |
# 3) add bars to foo | |
foo.bars = Bar.all(:id => [1,2]) | |
foo.save | |
# 4) update foo | |
foo.update(:name => "foo_update") | |
# 5) update relationship <<<<< ERRROR WITH padrino "web" | |
foo = Foo.first | |
foo.bars = Bar.all(:id => 3) | |
foo.save | |
# when update foo.bars from web, dm not destroy the relationship with bar_id = 1,2 | |
# but if i use padrino console, dm work well | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment