snowyu/loopback-component-auto-migrate.js

how do you suggest to seed related models?

jdhrivas opened this issue · 4 comments

Seed data without relationships works just fine, but when it comes to related model I noticed that even if I set the _id property, the migration still auto generates the id. This causes the relationships to break. I was wondering, how do you suggest to seed related models?

see the example:

- id: admin
  name: Admin
  username: admin
  password: 123456
  organizations: # the organization relation
    - organizationId: '/DevCo/#staff'
      other-fields-to-create: '....'
    - organizationId: '/Volteer/#staff'

@snowyu perfect, so you are just nesting objects within the same .json file. I'll give it a try, thanks

I have a similar question to above - how to add roles to a certain user? I've tried to add role directly to user, but it complains. what would be correct way to do that?

Sorry, I forgot the official way, I use my way: https://github.com/snowyu/loopback-component-role-user.js

# a-c-l.yaml
- model: 'Storage'
  property: 'create'
  accessType: '*'
  principalType: 'ROLE'
  principalId: 'Storage.add'
  permission: 'ALLOW'

- model: 'Storage'
  property: 'upsert'
  accessType: '*'
  principalType: 'ROLE'
  principalId: 'Storage.edit'
  permission: 'ALLOW'

- model: 'Storage'
  property: 'exists'
  accessType: '*'
  principalType: 'ROLE'
  principalId: 'Storage.view'
  permission: 'ALLOW'

- model: 'Storage'
  property: 'findById'
  accessType: '*'
  principalType: 'ROLE'
  principalId: 'Storage.view'
  permission: 'ALLOW'
#role.yaml

- name:  "storeManager"
  title: "File Store Manager"
  description: "the file store manager"
  roles:
    - "Storage.view"
    - "Storage.edit"
    - "Storage.find"