Skip to content

Instantly share code, notes, and snippets.

Avatar

Bram Jans bramj

View GitHub Profile
View keybase.md

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 Sep 25, 2015
Rails polymorphic HABTM relation
View polymorphic_HABTM_relation.rb
# 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