Skip to content

Instantly share code, notes, and snippets.

@airhorns
Created April 14, 2011 19:45
Show Gist options
  • Save airhorns/920313 to your computer and use it in GitHub Desktop.
Save airhorns/920313 to your computer and use it in GitHub Desktop.
(rdb:1) query.conditions
(book = #<Book @id=1 @name="Harry Potter">)
(rdb:1) query.conditions.first.subject
#<DataMapper::Associations::ManyToOne::Relationship:0x00000101152528
@required=true,
@key=false,
@child_model=BookTag,
@child_model_name="BookTag",
@parent_model_name="Book",
@name=:book,
@instance_variable_name="@book",
@options={:min=>1, :max=>1, :child_repository_name=>:default, :parent_repository_name=>nil},
@child_repository_name=:default,
@parent_repository_name=nil, @min=1, @max=1, @reader_visibility=:public, @writer_visibility=:public, @default=nil,
@query={},
@parent_model=Book,
@parent_key=[#<DataMapper::Property::Serial @model=Book @name=:id>],
@child_key=[#<DataMapper::Property::Integer @model=BookTag @name=:book_id>]>
(rdb:1) query.conditions.first.value
#<Book @id=1 @name="Harry Potter">
class Book
include DataMapper::Resource
property :id, Serial
property :name, String, :index => true
has n, :book_tags
has n, :tags, :through => :book_tags
end
class Tag
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :book_tags
has n, :books, :through => :book_tags
end
class BookTag
include DataMapper::Resource
property :id, Serial
belongs_to :book
belongs_to :tag
end
@b = Book.create(:name => "Harry Potter")
@t = Tag.create(:name => "fiction")
@t2 = Tag.create(:name => "wizards")
@b.tags << @t
@b.tags << @t2
@b.save
debugger # this is where I get the above output
@b.tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment