Created
March 5, 2011 11:35
-
-
Save rgarner/856304 to your computer and use it in GitHub Desktop.
dm-many-to-many weirdness
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
class Calendar | |
include DataMapper::Resource | |
has n, :events | |
property :id, Serial | |
property :slug, Slug | |
property :title, String | |
property :published, Boolean | |
property :created_at, DateTime | |
end | |
class Constraint | |
include DataMapper::Resource | |
has n, :events, :through => Resource | |
property :id, Serial | |
property :name, String | |
property :slug, String | |
end | |
class Event | |
include DataMapper::Resource | |
property :id, Serial | |
property :title, String | |
property :occurs_at, DateTime | |
belongs_to :calendar | |
has n, :constraints, :through => Resource | |
end | |
DataMapper.finalize.auto_migrate! | |
events = Event.all(Event.constraints.slug => params[:constraint_slug] ) | |
# results in | |
# DataMapper::UnknownRelationshipError: No relationships named event or event in ConstraintEvent | |
# If one then tries | |
constraints = Constraint.all(Constraint.events.title => 'something') | |
# then the error is different (the generated SQL does not include the joins) | |
# Basically, the first query to be called will fail, the second will fail with a different error, then the first will work! | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment