{"action":"created","issue":{"url":"https://api.github.com/repos/typeorm/typeorm/issues/46","repository_url":"https://api.github.com/repos/typeorm/typeorm","labels_url":"https://api.github.com/repos/typeorm/typeorm/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/typeorm/typeorm/issues/46/comments","events_url":"https://api.github.com/repos/typeorm/typeorm/issues/46/events","html_url":"https://github.com/typeorm/typeorm/issues/46","id":179584387,"number":46,"title":"Not loading data from @OneToOne relation","user":{"login":"19majkel94","id":10618781,"avatar_url":"https://avatars.githubusercontent.com/u/10618781?v=3","gravatar_id":"","url":"https://api.github.com/users/19majkel94","html_url":"https://github.com/19majkel94","followers_url":"https://api.github.com/users/19majkel94/followers","following_url":"https://api.github.com/users/19majkel94/following{/other_user}","gists_url":"https://api.github.com/users/19majkel94/gists{/gist_id}","starred_url":"https://api.github.com/users/19majkel94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/19majkel94/subscriptions","organizations_url":"https://api.github.com/users/19majkel94/orgs","repos_url":"https://api.github.com/users/19majkel94/repos","events_url":"https://api.github.com/users/19majkel94/events{/privacy}","received_events_url":"https://api.github.com/users/19majkel94/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-27T19:05:48Z","updated_at":"2016-09-29T11:56:07Z","closed_at":null,"body":"There is a problem with loading object from database. The creating and saving works (I looked in the database) but when loading from database it doesn't load the data from relation.\r\n\r\n```typescript\r\nimport \"reflect-metadata\";\r\n\r\nimport { createConnection } from \"typeorm\";\r\n\r\nimport { Post } from \"./post\";\r\nimport { PostDetails } from \"./post-details\";\r\n\r\nasync function main() {\r\n    try {\r\n        console.log(`Before connection!`);\r\n        let connection = await createConnection({\r\n            driver: {\r\n                type: \"mysql\",\r\n                host: \"localhost\",\r\n                port: 3306,\r\n                username: \"root\",\r\n                password: \"qwerty123\",\r\n                database: \"typeorm\"\r\n            },\r\n            entities: [\r\n                Post, PostDetails\r\n            ],\r\n            logging: {\r\n                logQueries: true,\r\n                logFailedQueryError: true,\r\n            },\r\n            autoSchemaSync: true,\r\n        });\r\n        console.log(`Connected!`);\r\n\r\n        let post = new Post();\r\n        post.title = \"Title\";\r\n        post.text = \"Lorem ipsum\";\r\n        post.details = new PostDetails();\r\n        post.details.testField = \"test\";\r\n        console.log(post);\r\n        post = await connection.getRepository(Post).persist(post);\r\n        console.log(post);\r\n        let loadedPost = await connection.getRepository(Post).findOneById(post.id);\r\n        console.log(loadedPost);\r\n\r\n        console.log(`Saved ok!`);\r\n        process.exit(0);\r\n    } catch (error) {\r\n        console.log(`Error!`, error);\r\n        process.exit(1);\r\n    }\r\n}\r\n\r\nmain();\r\n```\r\nMy entities:\r\n```typescript\r\nimport { Table, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn } from \"typeorm\";\r\nimport { PostDetails } from \"./post-details\";\r\n\r\n@Table()\r\nexport class Post {\r\n    @PrimaryGeneratedColumn()\r\n    public id: number;\r\n\r\n    @Column()\r\n    title: string;\r\n\r\n    @Column(\"text\")\r\n    text: string;\r\n\r\n    @JoinColumn()\r\n    @OneToOne(type => PostDetails, { cascadeInsert: true, nullable: true })\r\n    details: PostDetails | null;\r\n}\r\n```\r\n\r\n```typescript\r\nimport { Table, PrimaryGeneratedColumn, Column } from \"typeorm\";\r\n\r\n@Table()\r\nexport class PostDetails {\r\n    @PrimaryGeneratedColumn()\r\n    public id: number;\r\n\r\n    @Column()\r\n    testField: string;\r\n}\r\n```\r\nCreated object looks like this:\r\n```\r\nPost {\r\n  title: 'Title',\r\n  text: 'Lorem ipsum',\r\n  details: PostDetails { testField: 'test', id: 1 },\r\n  id: 1 }\r\n```\r\nBut it generates sql without joins on relation, so only id is returned not the data:\r\n`SELECT post.id AS post_id, post.title AS post_title, post.text AS post_text, post.details AS post_details FROM post post WHERE post.id=? -- PARAMETERS: [1]`\r\nSo the loaded object has empty `details` field:\r\n```\r\nPost { id: 1, title: 'Title', text: 'Lorem ipsum' }\r\n```\r\nThis is a bug or I should add some decorator in `PostDetails`?"},"comment":{"url":"https://api.github.com/repos/typeorm/typeorm/issues/comments/250445823","html_url":"https://github.com/typeorm/typeorm/issues/46#issuecomment-250445823","issue_url":"https://api.github.com/repos/typeorm/typeorm/issues/46","id":250445823,"user":{"login":"pleerock","id":1753397,"avatar_url":"https://avatars.githubusercontent.com/u/1753397?v=3","gravatar_id":"","url":"https://api.github.com/users/pleerock","html_url":"https://github.com/pleerock","followers_url":"https://api.github.com/users/pleerock/followers","following_url":"https://api.github.com/users/pleerock/following{/other_user}","gists_url":"https://api.github.com/users/pleerock/gists{/gist_id}","starred_url":"https://api.github.com/users/pleerock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pleerock/subscriptions","organizations_url":"https://api.github.com/users/pleerock/orgs","repos_url":"https://api.github.com/users/pleerock/repos","events_url":"https://api.github.com/users/pleerock/events{/privacy}","received_events_url":"https://api.github.com/users/pleerock/received_events","type":"User","site_admin":false},"created_at":"2016-09-29T11:56:07Z","updated_at":"2016-09-29T11:56:07Z","body":"> People use ORM to simplify data access - just use @Decorator and don't worry about foreing keys, joins and other stuffs.\r\n\r\nactually you are not worrying about keys or joins. You are just telling which relation you need to load.\r\n\r\nBut I got your point, I have some ideas how to add automatic joins, i'll try to implement them later. Until that use query builder or find options  "}}
{"actor":{"display_login":"pleerock"}}