Skip to content

Instantly share code, notes, and snippets.

View bramj's full-sized avatar

Bram Jans bramj

View GitHub Profile

Keybase proof

I hereby claim:

  • I am bramj on github.
  • I am bramj (https://keybase.io/bramj) on keybase.
  • I have a public key whose fingerprint is B5E1 8FCD 8432 F547 D9B7 8433 7CB3 379E E0F8 7B75

To claim this, I am signing this object:

@bramj
bramj / polymorphic_HABTM_relation.rb
Last active September 25, 2015 09:39
Rails polymorphic HABTM relation
# The problem: I needed to create bundles, to be able to sell collections of both courses as well as tracks. (and in the future possibly more things)
# But in return, a track/course can also belong to multiple bundles.
# So: bundle has_many tracks/courses, tracks/courses has_many bundles
# (This was work in progress, but if I remember correctly, it works.)
# app/models/bundle.rb
class Bundle < ActiveRecord::Base
# Creating a polymorphic HABTM relation in Rails is not possible,
# this does basically the same thing
has_many :bundles_bundleables # terrible naming