You are confusing a SQL query with a model attribute. Team.select('id')
is the first part of a query that will return the id of whatever team you are looking for. If you want to get the id of a team model, you just write team.id
, so your code should be mem.team.id
, where mem
is a model from the Mem
class and team
is a model from the Team
class.
Let me expound a little. You need some piece of information that is unique to your model in order to retrieve your model from the database. I am going to assume that you will be using the id
, but you can use any attribute or combinations of attributes.
Let's retrieve our models from the database:
star_player = Mem.find('5')
team_id = star_player.team.id
Two queries were executed, one that retrieved your team member using find
and another to retrieve the team id was performed automatically using the rails associations that you should have set up.