database - creating Models with sqlite3 + datamapper + ruby -
how build model following associations (i tried couldn't work):
each order has: customer, salesrep, many orderline each has item.
i tried: when do: customer.all(customer.orders.order_lines.item.sku.like => "%blue%") output :[]
instead of: '[#<"customer @id=1 @name="dan kubb">]'
when delete salesrep: works.
customer
has n, :orders
has n, :items, :through => :order
salesrep
has n, :orders
has n, :items, :through => :order
order
belongs_to :customer
belongs_to :technician
has n, :order_lines
has n, :items, :through => :order_line
orderline
belongs_to :order
belongs_to :item
item
has n, :order_lines
since output isn't error, don't have data in database.
try following irb -r your_models_file.rb
: - c = customer.create(:name => "dan kubb")
o = order.new(:customer => c) # create , add technician unless it's :required => false
i = item.create(:sku => "blue") # plus other required fields
ol = orderline.create(:order => o, :item => i)
o.order_lines << ol; o.save
that should create records needed work. try out, , if doesn't work, post entire models file can better idea of what's up.
Comments
Post a Comment