Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Model Associations

Model Associations

Model Associations

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)


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

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

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

class Seat < ActiveRecord::Base
    has_many :orders

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

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

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:


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)

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




Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close