{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3981","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3981/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3981/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3981/events","html_url":"https://github.com/sequelize/sequelize/issues/3981","id":89879094,"number":3981,"title":"findOrInitialize() with empty \"where\" option just returns first object from the DB.","user":{"login":"VasilioRuzanni","id":754993,"avatar_url":"https://avatars.githubusercontent.com/u/754993?v=3","gravatar_id":"","url":"https://api.github.com/users/VasilioRuzanni","html_url":"https://github.com/VasilioRuzanni","followers_url":"https://api.github.com/users/VasilioRuzanni/followers","following_url":"https://api.github.com/users/VasilioRuzanni/following{/other_user}","gists_url":"https://api.github.com/users/VasilioRuzanni/gists{/gist_id}","starred_url":"https://api.github.com/users/VasilioRuzanni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VasilioRuzanni/subscriptions","organizations_url":"https://api.github.com/users/VasilioRuzanni/orgs","repos_url":"https://api.github.com/users/VasilioRuzanni/repos","events_url":"https://api.github.com/users/VasilioRuzanni/events{/privacy}","received_events_url":"https://api.github.com/users/VasilioRuzanni/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-21T07:52:59Z","updated_at":"2015-06-21T10:16:55Z","closed_at":null,"body":"Sequelize: **3.2.0**, database: **Postgres**\r\n\r\nWith any model, the `findOrInitialize` method returns the first row in a database:\r\n\r\n```\r\nUser.findOrInitialize({\r\n  where: { id: undefined }, // or just where: {}\r\n  defaults: {\r\n    someAttr: 123,\r\n    ...\r\n  }\r\n}).then(function (user) {\r\n  // \"user\" is now just a first row from the database in Sequelize 3.2.0\r\n  // but it used to be an object initialized with \"defaults\" attribute in Sequelize 2.1.3\r\n});\r\n```\r\n\r\nFrom one side of the coin that might be justified - no `where` criteria is given so we can consider this case as \"no criteria\", assume that \"everything matches\" and return anything that matches first. From the other side, this method is only useful in cases when you need to initialize a new instance based on `defaults` when there is nothing to search for.\r\n\r\nIs this expected behavior or is a regression introduced in **3.2.0**?"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/113881742","html_url":"https://github.com/sequelize/sequelize/issues/3981#issuecomment-113881742","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/3981","id":113881742,"user":{"login":"janmeier","id":1210224,"avatar_url":"https://avatars.githubusercontent.com/u/1210224?v=3","gravatar_id":"","url":"https://api.github.com/users/janmeier","html_url":"https://github.com/janmeier","followers_url":"https://api.github.com/users/janmeier/followers","following_url":"https://api.github.com/users/janmeier/following{/other_user}","gists_url":"https://api.github.com/users/janmeier/gists{/gist_id}","starred_url":"https://api.github.com/users/janmeier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janmeier/subscriptions","organizations_url":"https://api.github.com/users/janmeier/orgs","repos_url":"https://api.github.com/users/janmeier/repos","events_url":"https://api.github.com/users/janmeier/events{/privacy}","received_events_url":"https://api.github.com/users/janmeier/received_events","type":"User","site_admin":false},"created_at":"2015-06-21T10:16:55Z","updated_at":"2015-06-21T10:16:55Z","body":"Definitely!"}}