Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code syntax highlighting for tutorials #1850

Merged
merged 2 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion tutorials/many-to-many.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Many-to-many associations can be created with {@link Model#belongsToMany belongsToMany}, and {@link Model#through through} relation types.

```js
var Book = bookshelf.Model.extend({
tableName: 'books',
authors: function() {
Expand All @@ -13,9 +14,10 @@ Many-to-many associations can be created with {@link Model#belongsToMany belongs
return this.belongsToMany(Book);
}
});

```
A Knex migration for the above relationship could be created with:

```js
exports.up = function(knex, Promise) {
return knex.schema.createTable('books', function(table) {
table.increments('id').primary();
Expand All @@ -34,3 +36,4 @@ A Knex migration for the above relationship could be created with:
.dropTable('authors')
.dropTable('authors_books');
};
```
5 changes: 4 additions & 1 deletion tutorials/one-to-many.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
One-to-many associations can be created with {@link Model#belongsTo belongsTo}, {@link Model#hasMany hasMany}, {@link Model#morphMany morphMany} / {@link Model#morphTo morphTo}, and some of the {@link Model#through through} relation types.

```js
var Book = bookshelf.Model.extend({
tableName: 'books',
pages: function() {
Expand All @@ -13,9 +14,10 @@ One-to-many associations can be created with {@link Model#belongsTo belongsTo},
return this.belongsTo(Book);
}
});

```
A Knex migration for the above relationship could be created with:

```js
exports.up = function(knex, Promise) {
return knex.schema.createTable('books', function(table) {
table.increments('id').primary();
Expand All @@ -31,3 +33,4 @@ A Knex migration for the above relationship could be created with:
return knex.schema.dropTable('books')
.dropTable('pages');
};
```
5 changes: 4 additions & 1 deletion tutorials/one-to-one.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
One-to-one associations can be created with {@link Model#belongsTo belongsTo}, {@link Model#hasOne hasOne}, and {@link Model#morphOne morphOne} relation types.

```js
var Book = bookshelf.Model.extend({
tableName: 'books',
summary: function() {
Expand All @@ -13,9 +14,10 @@ One-to-one associations can be created with {@link Model#belongsTo belongsTo}, {
return this.belongsTo(Book);
}
});

```
A Knex migration for the above relationship could be created with:

```js
exports.up = function(knex, Promise) {
return knex.schema.createTable('books', function(table) {
table.increments('id').primary();
Expand All @@ -31,3 +33,4 @@ A Knex migration for the above relationship could be created with:
return knex.schema.dropTable('books')
.dropTable('summaries');
};
```
4 changes: 4 additions & 0 deletions tutorials/parse-and-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ parse.
This can be done with the model's {@link Model#parse parse} and {@link Model#format format}
methods:

```js
Book = bookshelf.Model.extend({
tableName: 'books',
parse: function(response) {
Expand All @@ -16,9 +17,11 @@ methods:
return attributes;
}
});
```

A very common use case for this is converting camelCase attributes to snake_case column names and vice-versa:

```js
Book = bookshelf.Model.extend({
tableName: 'books',
parse: function(response) {
Expand All @@ -32,3 +35,4 @@ A very common use case for this is converting camelCase attributes to snake_case
});
}
});
```
2 changes: 2 additions & 0 deletions tutorials/polymorphic.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a photo model that belongs to either a `Site` model or a `Post` model. Here’s how this could be declared:

```js
var Site = bookshelf.Model.extend({
tableName: 'sites',
photo: function() {
Expand All @@ -20,6 +21,7 @@ With polymorphic associations, a model can belong to more than one other model,
return this.morphTo('imageable', Site, Post);
}
});
```

Optionally, if you wish to use column names other than the `name` suffixed with `_type` and `_id` (for example, if you use a different naming convention in your database), you may specify custom `columnNames`. This argument, when specified, expects an array containing the substitute `_type` and `_id` columns, respectively.

Expand Down