Created
January 25, 2011 17:26
-
-
Save jergason/795259 to your computer and use it in GitHub Desktop.
DataMapper association woes
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
module TruckPricer | |
class Engine | |
include DataMapper::Resource | |
property :id, Serial, :key => true | |
property :name, String, :required => true | |
property :vin_string, String | |
belongs_to :price, :required => false | |
end | |
end | |
module TruckPricer | |
class TruckModel | |
include DataMapper::Resource | |
property :id, Serial, :key => true | |
property :name, String, :required => true | |
property :vin_string, String | |
belongs_to :price, :required => false | |
end | |
end | |
#I want this model to contain the ids of the TruckModel and Engine models | |
require 'dm-serializer' | |
module TruckPricer | |
class Price | |
include DataMapper::Resource | |
property :id, Serial, :key => true | |
property :price, Float | |
has 1, :truck_model | |
has 1, :engine | |
end | |
end | |
#Would like to be able to look up Price by the TruckModel and Engine associated with it like so: | |
TruckPricer::Price.first(:truck_model_id => 1, :engine_id => 1) | |
#This fails because Price doesn't have truck_model_id or engine_id attributes. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment