title: Dilemma between two database schemas for my marketplace rails project
body: <p>I'm building a market place when a User can both buy and sell.
  Of course he will not be able to buy his own products and once one of his product will be buyed there will be a quantity logic controller behind. However. I'm still stuck at modeling the schema.</p>
  
  <p>At the moment i'm using this schema.</p>
  
  <pre><code>  ActiveRecord::Schema.define(version: 2018_09_11_202223) do
  
    create_table "categories", force: :cascade do |t|
      t.string "name"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
    end
  
    create_table "orders", force: :cascade do |t|
      t.integer "user_id"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.index ["user_id"], name: "index_orders_on_user_id"
    end
  
    create_table "orders_products", id: false, force: :cascade do |t|
      t.integer "order_id", null: false
      t.integer "product_id", null: false
      t.index ["order_id", "product_id"], name: "index_orders_products_on_order_id_and_product_id"
      t.index ["product_id", "order_id"], name: "index_orders_products_on_product_id_and_order_id"
    end
  
    create_table "products", force: :cascade do |t|
      t.string "name"
      t.string "tagline"
      t.integer "user_id"
      t.integer "category_id"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.integer "price"
      t.text "description"
      t.index ["category_id"], name: "index_products_on_category_id"
      t.index ["user_id"], name: "index_products_on_user_id"
    end
  
    create_table "users", force: :cascade do |t|
      t.string "email", default: "", null: false
      t.string "encrypted_password", default: "", null: false
      t.string "reset_password_token"
      t.datetime "reset_password_sent_at"
      t.datetime "remember_created_at"
      t.integer "sign_in_count", default: 0, null: false
      t.datetime "current_sign_in_at"
      t.datetime "last_sign_in_at"
      t.string "current_sign_in_ip"
      t.string "last_sign_in_ip"
      t.datetime "created_at", null: false
      t.datetime "updated_at", null: false
      t.index ["email"], name: "index_users_on_email", unique: true
      t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
    end
  
  end
  </code></pre>
  
  <p>Whit these models: </p>
  
  <pre><code>class Category &lt; ApplicationRecord
    has_many :products
  end
  
  class Order &lt; ApplicationRecord
    has_and_belongs_to_many :products
    belongs_to :user
  end
  
  class Product &lt; ApplicationRecord
    has_and_belongs_to_many :orders
    belongs_to :category
    belongs_to :user
  end
  
  class User &lt; ApplicationRecord
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :validatable
    has_many :orders, :dependent =&gt; :destroy
    has_many :products, :dependent =&gt; :destroy
  end
  </code></pre>
  
  <p>So basically i'm about to use a HABTOM (has_and_belongs_to_many) associations between the table Orders and Products as you can see inside my models, because an order can have many products and a product can be in many orders( here i'm not sure xD, i think i'm wrong ). Anyway, my dilemma is this, since i've read on internet that in the most of the cases, in situations like this you can use the has_many :through association (HMTA), something  like this:</p>
  
  <pre><code>class Category &lt; ApplicationRecord
    has_many :products
  end
  
  class User
    has_many :orders
    has_many :products, through: :orders
  end
  
  class Order
    belongs_to :user
    belongs_to :product
  end
  
  class Product
    belongs_to :category
    has_many :orders
    has_many :users, through: :orders
  end
  </code></pre>
  
  <p>keep in mind that in my marketplace i want the people can both buy and sell, that's why a User can have many products but <strong>the product must be unique and should belong to only one specific User</strong>, for instance an old car, doesn't exist two cars exactly identical, that's why i used this association in my Product model:</p>
  
  <pre><code>class Product &lt; ApplicationRecord
    has_and_belongs_to_many :orders
    belongs_to :category
    belongs_to :user
  end
  </code></pre>
  
  <p>so in the end what do you suggest me to do? should i switch from the HABTOM association to a HMTA? In this case, let's say i want to sell a product, how can i manage the User and Product association? is it possible just using a has_many :through association? Thank you</p>