Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Model Associations

Status
Not open for further replies.

jman78

Programmer
Jan 15, 2008
44
US
I'm trying to create a simple POS (Point of Sale) system.

I have associations set up in the order models to the items and seats (tables)

Code:
class Order < ActiveRecord::Base
	has_many :order_splits
	has_many :order_split_items, :through => :order_splits
	belongs_to :seat, :foreign_key => 'table_id'
end

class OrderSplit < ActiveRecord::Base
	belongs_to :order
	belongs_to :order_split_item
end

class OrderSplitItem < ActiveRecord::Base
	belongs_to :items
	has_many :order_splits
	has_many :orders, :through => :order_splits
end

class Seat < ActiveRecord::Base
	has_many :orders
end

class Item < ActiveRecord::Base
	belongs_to :item_category
	belongs_to :order_split_item
end

class ItemCategory < ActiveRecord::Base
	has_many :items
	#has_many :modifiers            #ignore for now
	#has_many :modifier_attributes  #ignore for now 
end

Each Order has one to several order_splits and each order_split is comprised of one to several order_split_items. Each Order is set to one seat(table) via the key order.'table_id' -> 'seat.id' . do I need attr_accessors for everything? Is that the problem or do I need to change the associations I set up?

I'm getting errors when I try to reference any settings on the order object once it is saved.

my controller code that saves is:
Code:
def show_menu 
#creates order and order_split (seat at the table)
...
@new_order = Order.new(:server_id => @server_id, :table_id => @table_id, :guest_count => @guest_count)
	  	session[:order] = @new_order if @new_order.save
	  	
	  	@order_split = OrderSplit.new(:order_id => @new_order.id, :seat => @table_seat)
end

def add_item
@order_split_item = OrderSplitItem.new(:order_split_id => params[:order_split_id], :item_id => params[:item_id], :quantity => params[:quantity])
 item_saved = false 
 item_saved = true if @order_split_item.save
	
 if item_saved
    @split_item = @order_split_item 
    @split_item[:name] = @order_split_item.item_name #errors here
    @split_item[:price] = @order_split_item.price
 end 
 ...
end

Thanks,

Jason

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top