title: PostgreSql - Many to Many relations
body: <p>i am fairly new to postgres and trying to create database model's for a app user typeorm.I have a item(product) model and user model.A user can save multiple items to their wishlist/favourutes and one item can be saved by multiple users as well. I am having problem in creating a SavedItems table which will consist info about which user have saved what item. My query is should i create a third model <code>SavedItems</code> or use <code>@JoinTable</code> which creates a table automatically?</p>
  <pre><code>**Item model**
  @Entity()
  export default class Item extends Base {
  
  @Column()
  @Index()
  user_id: number
  
  @ManyToOne(() =&gt; User, user =&gt; user.items, {onDelete: 'CASCADE'})
  @JoinColumn({name: 'user_id', referencedColumnName: 'id'})
  user: User
  
  @Column()
  images: Array&lt;string&gt;
  
  @Column()
  description: string
  
  @Column()
  brand: string
  
  @Column()
  item_type: string
  
  @Column()
  material: string
  
  @Column()
  length: number
  
  @Column()
  neckline: string
  
  @Column()
  sleeve_length: number
  
  @Column()
  body_fit: string
  
  @Column()
  size: number
  
  @Column()
  colors: Array&lt;string&gt;
  
  @Column()
  hire_price: number
  
  @Column()
  retail_price: number
  
  @Column()
  dry_cleaning_price: number
  
  @Column()
  bond_price: number
  
  @Column()
  @Index()
  category_id:number
  
  @ManyToOne(() =&gt; Category, category =&gt; category.items, {onDelete: 'CASCADE'})
  @JoinColumn({name: 'category_id', referencedColumnName: 'id'})
  category: Category
  
  @Column()
  @Index()
  sub_category_id: number 
  
  @ManyToOne(() =&gt; SubCategory, sub_category =&gt; sub_category.items, {onDelete: 'SET NULL'})
  @JoinColumn({name: 'sub_category_id', referencedColumnName: 'id'})
  sub_category: SubCategory
  
  @Column()
  @Index()
  rating: number
  
  @Column()
  is_available: boolean
  
  @Column()
  hire_period: number
  
  @Column()
  additional_per_day_cost: number
  
  @Column()
  model_id: number
  
  @ManyToOne(() =&gt; ModelProfile, model_profile =&gt; model_profile.items, {onDelete: 'SET NULL'})
  @JoinColumn({name: 'model_id', referencedColumnName: 'id'})
  model: ModelProfile
  
  @Column('int')
  status: status
  
  @Column()
  reason: string
  
  @Column()
  orders_accpeted_in: string
  
  @Column()
  global_countries: Array&lt;string&gt;
  
  @Column()
  contact_first_name: string
  
  @Column()
  contact_last_name: string
  
  @Column()
  contact_country_code: string
  
  @Column()
  contact_mobile_number: string
  
  @Column()
  address_id: number
  
  @Column()
  is_trending:boolean
  
  @ManyToOne(() =&gt; Address, address =&gt; address.items, {onDelete: 'SET NULL'})
  @JoinColumn({name: 'address_id', referencedColumnName: 'id'})
  address: Address
  
  
  @OneToMany(() =&gt; ItemDelivery, item_delivery =&gt; item_delivery.item)
  delivery_options: ItemDelivery[]
  
  @OneToMany(() =&gt; ItemReports, item_reports =&gt; item_reports.item_id)
  reports: ItemReports[]
  
  @OneToMany(() =&gt; ItemViews, item_views =&gt; item_views.item)
  views: ItemViews[]
  
  @ManyToMany(() =&gt; Order, order =&gt; order.items)
  orders: Order[]
  
  @OneToMany(() =&gt; Reward, reward =&gt; reward.item)
  rewards: Reward[]
  // @ManyToMany(() =&gt; User, user =&gt; user.saved_items )
  
  
  }
  </code></pre>
  <p><strong>User model</strong></p>
  <pre><code>@Entity()
  export default class User extends Base {
  
  
  @Column()
  full_name: string
  
  @Column()
  username: string
  
  @Column()
  display_name: string
  
  @Column()
  profile_image: string
  
  @Column()
  cover_image: string
  
  @Column()
  @Index()
  email: string
  
  @Column()
  is_email_verified: boolean
  
  @Column()
  country_code: string
  
  @Column()
  phone_number: string
  
  @Column({select: false})
  password: string
  
  @Column()
  two_factor_auth: boolean
  
  @Column()
  two_factor_text: string
  
  @Column()
  otp: string
  
  @Column()
  otp_sent_at: string
  
  @Column()
  verification_level: string
  
  @Column()
  dob: Date
  
  @Column()
  is_disable: boolean
  
  @Column()
  disable_reason: string
  
  @Column()
  stripe_customer_id: string
  
  @Column()
  is_driver_license_verified: boolean
  
  @Column()
  is_postal_address_verified: boolean
  
  @Column()
  default_location: Geometry
  
  @Column()
  default_dress_size: string
  
  @Column()
  default_shoes_size: string
  
  @Column()
  redeem_points: string
  
  @Column()
  invite_link: string
  
  @Column()
  last_active: Date
  
  @Column()
  seller_link: string
  
  @Column()
  is_blocked: boolean
  
  @Column()
  is_holiday_mode: boolean
  
  @Column()
  holiday_mode_start: Date
  
  @Column()
  holiday_timezone: string
  
  @Column()
  is_trending: boolean
  
  @OneToMany(() =&gt; Item, item =&gt; item.user)
  items: Item[]
  
  @OneToOne(() =&gt; ModelProfile, model_profile =&gt; model_profile.user)
  model: ModelProfile
  
  @OneToMany(() =&gt; Address, address =&gt; address.user)
  address: Address[]
  
  @OneToMany(() =&gt; Order, order =&gt; order.buyer)
  buy_orders: Order
  
  @OneToMany(() =&gt; Order, order =&gt; order.seller)
  sell_orders: Order
  
  @OneToMany(() =&gt; Conversation, conversation =&gt; conversation.sender)
  conversations_initiated: Conversation[]
  
  @OneToMany(() =&gt; Conversation, conversation =&gt; conversation.receiver)
  conversations_partner: Conversation[]
  
  @OneToMany(() =&gt; Messages, messages =&gt; messages.sender_id)
  message_sent : Messages[]
  
  @OneToMany(() =&gt; Messages, messages =&gt; messages.receiver_id)
  message_received : Messages[]
  
  @OneToMany(() =&gt; ItemViews, item_views =&gt; item_views.item)
  viewed_items: ItemViews[]
  
  @OneToMany(() =&gt; ItemReports, item_reports =&gt; item_reports.item)
  item_reports: ItemReports[]
  
  @OneToMany(() =&gt; ModelClaims, model_claims =&gt; model_claims.user)
  model_profile_claim: ModelClaims[]
  
  @OneToMany(() =&gt; BlockedUsers, blocked_users =&gt; blocked_users.user)
  blocked_users: BlockedUsers[]
  
  @OneToMany(()=&gt; BlockedUsers, blocked_users =&gt; blocked_users.blocked_user_id)
  blocked_by: BlockedUsers[]
  
  @OneToMany(()=&gt; ModelReports, model_reports =&gt; model_reports.model)
  model_reports: ModelReports[]
  
  @OneToMany(() =&gt;UserVerificationRequests, user_verification_requests =&gt; user_verification_requests.user)
  verification_requests: UserVerificationRequests[]
  
  @OneToMany(() =&gt; UserReports, user_reports =&gt; user_reports.user)
  user_reports: UserReports
  
  @OneToMany(() =&gt; UserReports, user_reports =&gt; user_reports.reported_user)
  reports_received: UserReports
  
  @OneToMany(() =&gt; Session, session =&gt; session.user)
  sessions: Session[]    
  
  }
  </code></pre>