Skip to content

Instantly share code, notes, and snippets.

View mojo706's full-sized avatar
🎊
PRs for Everyone

Eugene Omar mojo706

🎊
PRs for Everyone
View GitHub Profile
@zcaceres
zcaceres / Include-in-Sequelize.md
Last active January 8, 2024 07:14
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).

When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.

Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.

So let's go through the one query that's worth memorizing to handle your eager loading.

The Basic Query

@vanpelt
vanpelt / channels.php
Created August 21, 2012 22:06
PHP sample code
//Initiation code (should be in 1 file)
$json = $_POST['payload']
$secret = "your_secret_key_in_the_settings_page"
$obj = json_decode($json)
if(sha1($json+$secret) == $_POST['signature']) {
if(some_function_that_checks_if_a_uid_is_valid_by_checking_your_database($obj['uid'])) {
$conversion_id = some_function_that_generates_and_stores_a_conversion_id_with_the_amount($obj['amount'])
echo $conversion_id
} else {
@hdiedrich
hdiedrich / install-r15b01.sh
Created June 12, 2012 13:59 — forked from rkmax/install-r15b.sh
Script to install Erlang R15B01 (tested on a fresh Ubuntu 12.04 install)
# You will need to make this file executable (chmod u+x) and run it with sudo
apt-get update
apt-get --fix-missing -y install build-essential m4 libncurses5-dev libssh-dev unixodbc-dev libgmp3-dev libwxgtk2.8-dev libglu1-mesa-dev fop xsltproc default-jdk
mkdir -p /src/erlang
cd /src/erlang
wget http://www.erlang.org/download/otp_src_R15B01.tar.gz
tar -xvzf otp_src_R15B01.tar.gz
chmod -R 777 otp_src_R15B01
cd otp_src_R15B01
./configure