-
Notifications
You must be signed in to change notification settings - Fork 153
DataMapper FAQ
Herein lies a list of commonly encountered questions, and perhaps even some answers. This FAQ is intended as a landing page for questions, as well as a location where specific questions answered in #datamapper on freenode, or on the mailing list can be pulled in to be shaped into general answers to problems. Questions and Answers as a result will remain in one of 3 states:
- Unanswered questions.
- Questions answered (either partially or fully) with links or conversations.
- Questions answered with prose here in this document.
The DataMapper irc channel logs can be found on irclogger, and tips and other questions and answers can be found with Alfred. Eventually this document will be used as source material for writing broader documentation for DataMapper, so your questions do matter! Please add questions or answers as you can.
Q) Can you use dm-migrations together with `DataMapper.auto_migrate!` or `DataMapper.auto_upgrade!`?
A) Yes! you can.
A) Yes! Not only can you query through a relationship, you can query through multiple relationships, down to the property level. Example:
Person.all(:pets=>Pet.first(:name=>"Bo", :breed=>"Portuguese Water Dog"))
# => the Obama family
Person.all("pets.breed"=>"Scottish Terrier") # using string based relationship targeting
# => GWB and family
# searching through multiple relationships using properties and query operators.
Building.all("floors.rooms.square_footage.gt"=>1000)
There’s at least the dm-is-read_only plugin by postmodern
Q) “I’m trying to set a relationship has n, :bars, :through => :bazes for my class Foo, but DM says it can’t find model ‘BarFoo’ when i auto_migrate!”:#has_n_through_model_missing
A) Foo has to have a relationship declared with Baz before you can have a relationship through it.
class Foo
include DataMapper::Resource
property :id, Serial
has n, :bazes, "Baz" # explicitly specifying Baz just to make sure DataMapper doesn't get hung up on inflection
has n, :bars, :through => :bazes
end
class Bar
include DataMapper::Resource
property :id, Serial
has n, :bazes, "Baz"
has n, :foos, :through => :bazes
end
class Baz
include DataMapper::Resource
belongs_to :foo
belongs_to :bar
end