7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Railsのjoinsでplaceholderを使う

7
Last updated at Posted at 2014-04-18

Railsのjoinsでplaceholderを使う

team_code='team_A'に所属するメンバーを取得する場合

class User < ActiveRecord::Base
  def self.join_team(team_code)
	User.joins(sanitize_sql_array(['INNER JOIN teams ON team_code = ?', team_code]))
  end
end

呼び出し側

User.join_team('teem_A').where('users.team_id = team.id')
7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?