Last active
December 22, 2015 02:39
-
-
Save mschwartz/6405201 to your computer and use it in GitHub Desktop.
Not shared content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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