Model Associations

I’m trying to create a simple POS (Point of Sale) system using rails
3, ruby 1.8.7

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

#order.table_id associates to seat.id
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

On 6 April 2011 04:06, Jason [email protected] wrote:

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

That should be has_many, not belongs_to (or it is wrong in Item below).

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs