Skip to content

Instantly share code, notes, and snippets.

@mschwartz
Last active December 22, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mschwartz/6405201 to your computer and use it in GitHub Desktop.
Save mschwartz/6405201 to your computer and use it in GitHub Desktop.
Not shared content
Schema.add({
name: 'Content',
fields: [
{ name: 'contentId', type: 'int', autoIncrement: true, defaultValue: 0 },
{ name: 'churchId', type: 'int' },
{ name: 'seoFriendly', type: 'varchar', size: 255 },
{ name: 'title', type: 'varchar', size: 255, defaultValue: 'Untitled' },
{ name: 'description', type: 'varchar', size: 255, defaultValue: 'No description' },
{ name: 'body', type: 'longtext' }
],
primaryKey: 'contentId',
indexes: [
'seoFriendly',
'churchId'
]
});
Schema.add({
name: 'Churches',
fields: [
{ name: 'churchId', type: 'int', autoIncrement: true, defaultValue: 0 },
{ name: 'churchName', type: 'varchar', size: 255, defaultValue: 'Unknown' },
],
primaryKey: 'churchId'
});
// get all content related to a specific church
Schema.find('Content', { churchId: req.sesion.churchId });
// get the current Church info:
Schema.find('Churches', { churchId: req.session.churchId });
// "join" the two tables
// method 1
var joined = Schema.find('Content', { churchId: req.session.churchId }).extend(Schema.find('Churches', { churchId: req.session.churchId }));
// method 2
var example = { churchId: req.session.churchId };
var joined = Schema.find('Content', example).extend(Schema.find('Churches', example));
// method 3
var churchId = req.session.churchId;
var joined = SQL.getDataRow('SELECT * FROM Content,Churches WHERE Content.churchId='+churchId+' AND Churches.churchId='+churchId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment