Skip to content

Instantly share code, notes, and snippets.

@andrejewski
Created March 29, 2018 13:51
Show Gist options
  • Select an option

  • Save andrejewski/0e6544c4fc722976ce130038eef08e55 to your computer and use it in GitHub Desktop.

Select an option

Save andrejewski/0e6544c4fc722976ce130038eef08e55 to your computer and use it in GitHub Desktop.
Scratch of how to solve the polymorphic association problem generically
/*
select table_name
from information_schema.tables
where table_type = 'BASE TABLE' and table_schema = 'public';
resources {
id serial primary key,
type text not null
}
comments {
id integer primary key references resources (id),
parent_id integer not null references resources (id),
root_id integer references comments (id),
content text not null
}
tags {
id integer primary key references resources (id),
parent_id integer not null references resources (id),
name text not null
}
audits {
id integer primary key references resources (id),
target_id integer not null references resources (id),
actor_id integer not null references users (id),
action_type text not null,
action_data jsonb not null,
ip_address text not null
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment