{"action":"created","issue":{"url":"https://api.github.com/repos/coleifer/peewee/issues/743","labels_url":"https://api.github.com/repos/coleifer/peewee/issues/743/labels{/name}","comments_url":"https://api.github.com/repos/coleifer/peewee/issues/743/comments","events_url":"https://api.github.com/repos/coleifer/peewee/issues/743/events","html_url":"https://github.com/coleifer/peewee/pull/743","id":114488094,"number":743,"title":"Foreign key to the composite primary key","user":{"login":"Maillol","id":2394534,"avatar_url":"https://avatars.githubusercontent.com/u/2394534?v=3","gravatar_id":"","url":"https://api.github.com/users/Maillol","html_url":"https://github.com/Maillol","followers_url":"https://api.github.com/users/Maillol/followers","following_url":"https://api.github.com/users/Maillol/following{/other_user}","gists_url":"https://api.github.com/users/Maillol/gists{/gist_id}","starred_url":"https://api.github.com/users/Maillol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Maillol/subscriptions","organizations_url":"https://api.github.com/users/Maillol/orgs","repos_url":"https://api.github.com/users/Maillol/repos","events_url":"https://api.github.com/users/Maillol/events{/privacy}","received_events_url":"https://api.github.com/users/Maillol/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-01T19:38:36Z","updated_at":"2015-11-02T14:56:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/coleifer/peewee/pulls/743","html_url":"https://github.com/coleifer/peewee/pull/743","diff_url":"https://github.com/coleifer/peewee/pull/743.diff","patch_url":"https://github.com/coleifer/peewee/pull/743.patch"},"body":"Create unit test in order to reproduce bug when we create foreign key to the\r\ncomposite primary key."},"comment":{"url":"https://api.github.com/repos/coleifer/peewee/issues/comments/153042429","html_url":"https://github.com/coleifer/peewee/pull/743#issuecomment-153042429","issue_url":"https://api.github.com/repos/coleifer/peewee/issues/743","id":153042429,"user":{"login":"coleifer","id":119974,"avatar_url":"https://avatars.githubusercontent.com/u/119974?v=3","gravatar_id":"","url":"https://api.github.com/users/coleifer","html_url":"https://github.com/coleifer","followers_url":"https://api.github.com/users/coleifer/followers","following_url":"https://api.github.com/users/coleifer/following{/other_user}","gists_url":"https://api.github.com/users/coleifer/gists{/gist_id}","starred_url":"https://api.github.com/users/coleifer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coleifer/subscriptions","organizations_url":"https://api.github.com/users/coleifer/orgs","repos_url":"https://api.github.com/users/coleifer/repos","events_url":"https://api.github.com/users/coleifer/events{/privacy}","received_events_url":"https://api.github.com/users/coleifer/received_events","type":"User","site_admin":false},"created_at":"2015-11-02T14:56:00Z","updated_at":"2015-11-02T14:56:00Z","body":"I've waffled about this some. I dislike implicitly creating the columns. Additionally, when querying, things seem like they might get a little weird, e.g.:\r\n\r\n```python\r\nclass Person(Model):\r\n    first_name = CharField()\r\n    last_name = CharField()\r\n    class Meta:\r\n        primary_key = CompositeKey('first_name', 'last_name')\r\n\r\n# API from your PR:\r\nclass Pet(Model):\r\n    owner = ForeignKeyField(Person)\r\n\r\n# API I had considered:\r\nclass Pet(Model):\r\n    owner_first_name = CharField()\r\n    owner_last_name = CharField()\r\n    owner = CompositeForeignKey(Person)\r\n```\r\n\r\nEach has its downsides. In the former, the related person's first and last name, which are present on the Pet, are abstracted away and not easily accessible. In the latter, I'm left wondering how useful that `owner` attribute is really going to be."}}