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

docs(repository): add hasOne relation docs #2161

Merged
merged 1 commit into from
Dec 19, 2018
Merged

Conversation

b-admike
Copy link
Contributor

@b-admike b-admike commented Dec 14, 2018

Add docs for hasOne relation. Related to #1422.

Checklist

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

@b-admike b-admike self-assigned this Dec 14, 2018
@b-admike
Copy link
Contributor Author

Builds failing because of #2159 (comment).


1. Make `supplierId` property or column a foreign key which references the `id`
from Supplier model's `id` property:
- `alter table <databaseName>.Account add foreign key (supplierId) REFERENCES <databaseName>.Supplier(id);`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a fenced block using triple back-ticks instead of using inline code.

Also I believe the usual convention is to use all-upper-case letters for SQL commands, e.g. ALTER TABLE.

@b-admike
Copy link
Contributor Author

@bajtos LGTY now? @raymondfeng @strongloop/loopback-maintainers PTAL.

Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

key on the source model and a unique constraint on the same column/key to ensure
one-to-one mapping. This relation indicates that each instance of the declaring
or source model has exactly one instance of the target model. Let's take an
example where an application has models supplier and account and a supplier can
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: shall we wrap the model name with backticks? Or start with upper case, like Supplier Account.

- Declare a property with the factory function type
`HasOneRepositoryFactory<targetModel, typeof sourceModel.prototype.id>` on the
source repository class.
- call the `createHasOneRepositoryFactoryFor` function in the constructor of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Call

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createHasOneRepositoryFactoryFor does not exist. For some reason _createHasOneRepositoryFactoryFor does. Is this correct?

@b-admike b-admike force-pushed the docs/hasone-relation branch 3 times, most recently from e703494 to 9e81c3c Compare December 19, 2018 18:07
@b-admike b-admike force-pushed the docs/hasone-relation branch from 9e81c3c to e07ccaf Compare December 19, 2018 18:26
@b-admike b-admike merged commit 8a83f81 into master Dec 19, 2018
@b-admike b-admike deleted the docs/hasone-relation branch December 19, 2018 18:50
1. Make `supplierId` property or column a foreign key which references the `id`
from Supplier model's `id` property:

```sql
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will put the code block outside of the list. To keep it inside the current list item, you need to indent it by 4 spaces. Same comment applies to the next two lines and also the other SQL block below (lines 148-150).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants