Created
January 9, 2012 19:09
-
-
Save pnomolos/1584408 to your computer and use it in GitHub Desktop.
Non-working has 1, :through => :model relationship
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
require 'data_mapper' | |
DataMapper::Logger.new($stdout) | |
DataMapper.setup(:default, 'sqlite::memory:') | |
class Pack | |
include DataMapper::Resource | |
belongs_to :school | |
has n, :pack_orders | |
property :id, Serial | |
end | |
class PackOrder | |
include DataMapper::Resource | |
belongs_to :pack | |
has 1, :school, :through => :pack | |
# I tried :belongs_to but DM throws an | |
# error about using :through with belongs_to | |
property :id, Serial | |
end | |
class School | |
include DataMapper::Resource | |
has n, :packs | |
has n, :pack_orders, :through => :packs | |
property :id, Serial | |
end | |
DataMapper.finalize | |
DataMapper.auto_migrate! | |
@school = School.create | |
@pack = Pack.create :school => @school | |
@pack_order = PackOrder.create :pack => @pack | |
# Works | |
@orders = PackOrder.all :pack => { :school => @school } | |
@orders.each do |order| | |
puts order.id | |
end | |
# Doesn't work | |
@orders = PackOrder.all :school => @school | |
@orders.each do |order| | |
puts order.id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment