{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/20744","labels_url":"https://api.github.com/repos/rails/rails/issues/20744/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/20744/comments","events_url":"https://api.github.com/repos/rails/rails/issues/20744/events","html_url":"https://github.com/rails/rails/issues/20744","id":92148341,"number":20744,"title":"Model.joins silently ignores where chaining","user":{"login":"thesmart","id":280877,"avatar_url":"https://avatars.githubusercontent.com/u/280877?v=3","gravatar_id":"","url":"https://api.github.com/users/thesmart","html_url":"https://github.com/thesmart","followers_url":"https://api.github.com/users/thesmart/followers","following_url":"https://api.github.com/users/thesmart/following{/other_user}","gists_url":"https://api.github.com/users/thesmart/gists{/gist_id}","starred_url":"https://api.github.com/users/thesmart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thesmart/subscriptions","organizations_url":"https://api.github.com/users/thesmart/orgs","repos_url":"https://api.github.com/users/thesmart/repos","events_url":"https://api.github.com/users/thesmart/events{/privacy}","received_events_url":"https://api.github.com/users/thesmart/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-30T17:16:32Z","updated_at":"2015-06-30T17:22:00Z","closed_at":"2015-06-30T17:22:00Z","body":"Model.joins seems to be ignoring where clauses chained after the first.  I would have expected this to work, or at least an error raised if additional where chaining isn't supported.  I am using activerecord 4.2.3.\r\n\r\nI have three tables: ```users```, ```teams```, and ```user_teams```.  Here is an example of the problem:\r\n```ruby\r\ndef self.select_teams_where(user_id, team_id = nil)\r\n  clause = Team.joins('INNER JOIN team_users ON team_users.team_id = teams.id').where(['team_users.user_id = ?', user_id])\r\n  clause.where(['team_users.team_id = ?', team_id]) if team_id\r\n  clause\r\nend\r\n```\r\n\r\nThis would allow for grabbing all Teams associated w/ User, or just one Team that matches the team_id.  When I call:\r\n\r\n```ruby\r\nTeamUser.select_teams_where(1, 1)\r\n```\r\n\r\nPostgreSQL gets the following query:\r\n\r\n```sql\r\nSELECT \"teams\".* FROM \"teams\" LEFT OUTER JOIN team_users ON team_users.team_id = teams.id WHERE (team_users.user_id = 1)\r\n```\r\n\r\nI expected to see an AND portion added to the WHERE clause for the team_id.  Instead, it appears the where chain is silently ignoring additional calls to where."},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/117267402","html_url":"https://github.com/rails/rails/issues/20744#issuecomment-117267402","issue_url":"https://api.github.com/repos/rails/rails/issues/20744","id":117267402,"user":{"login":"thesmart","id":280877,"avatar_url":"https://avatars.githubusercontent.com/u/280877?v=3","gravatar_id":"","url":"https://api.github.com/users/thesmart","html_url":"https://github.com/thesmart","followers_url":"https://api.github.com/users/thesmart/followers","following_url":"https://api.github.com/users/thesmart/following{/other_user}","gists_url":"https://api.github.com/users/thesmart/gists{/gist_id}","starred_url":"https://api.github.com/users/thesmart/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thesmart/subscriptions","organizations_url":"https://api.github.com/users/thesmart/orgs","repos_url":"https://api.github.com/users/thesmart/repos","events_url":"https://api.github.com/users/thesmart/events{/privacy}","received_events_url":"https://api.github.com/users/thesmart/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T17:22:00Z","updated_at":"2015-06-30T17:22:00Z","body":"Doh, I forgot that clause.where RETURNS a new clause, but doesn't not MODIFY the clause.  Ignore."}}