{"action":"closed","issue":{"url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/507","labels_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/507/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/507/comments","events_url":"https://api.github.com/repos/strongloop/loopback-datasource-juggler/issues/507/events","html_url":"https://github.com/strongloop/loopback-datasource-juggler/issues/507","id":61721818,"number":507,"title":"Default foreignKey field type on polymorphic belongsTo should be modelTo idType, not modelFrom idType","user":{"login":"doublemarked","id":239190,"avatar_url":"https://avatars.githubusercontent.com/u/239190?v=3","gravatar_id":"","url":"https://api.github.com/users/doublemarked","html_url":"https://github.com/doublemarked","followers_url":"https://api.github.com/users/doublemarked/followers","following_url":"https://api.github.com/users/doublemarked/following{/other_user}","gists_url":"https://api.github.com/users/doublemarked/gists{/gist_id}","starred_url":"https://api.github.com/users/doublemarked/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doublemarked/subscriptions","organizations_url":"https://api.github.com/users/doublemarked/orgs","repos_url":"https://api.github.com/users/doublemarked/repos","events_url":"https://api.github.com/users/doublemarked/events{/privacy}","received_events_url":"https://api.github.com/users/doublemarked/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-15T00:45:54Z","updated_at":"2015-03-18T23:06:06Z","closed_at":"2015-03-18T23:06:06Z","body":"Hello!\r\n\r\nRan into a problem today under the following conditions,\r\n\r\n1. MongoDB as a dataStore\r\n2. Polymorphic relation between **ModelA** and **ModelB**,\r\n  1. **ModelA** hasMany polymorphic **ModelB**\r\n  2. **ModelB** belongsTo polymorphic **ModelA**\r\n3. **ModelB** has a id key that differs in type from that of **ModelA**. For example, ``string``.\r\n\r\nOn call to ``ModelA.hasMany(...)``, the **ModelB** foreignKey field is auto-vivified with type ``ObjectID``.\r\nOn subsequent call to ``ModelB.belongsTo(...)``, the foreignKey field is redefined as the ``ModelB.id`` field type (such as  ``string``). \r\n\r\n**Expected behavior: the foreignKey field type for a polymorphic belongsTo should default to the modelTo idType.**\r\n\r\nSee the following project to reproduce: https://github.com/doublemarked/loopback-polymorphic-belongsTo-default-types\r\n\r\nThe relative code is at [relation-definition.js#L1131-L1132](https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/relation-definition.js#L1131-L1132)\r\n\r\n"}}