Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6023359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:59:36+00:00 2026-05-23T03:59:36+00:00

I have 2 models ( player and team linked through the model lnkteamplayer )

  • 0

I have 2 models (player and team linked through the model lnkteamplayer)

Team has_many players through lnkteamplayer
Player has_many teams through lnkteamplayer

I need to retrieve all players not belonging to a specific team.

<% @players = Player.find(:all, :conditions => ["id != ?",@team.lnkteamplayers.player_id ]) %>

I am getting an error with above line of code. My question is how do i pass an array of values in the above condition.

Thanks for any suggestion provided.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:59:36+00:00Added an answer on May 23, 2026 at 3:59 am

    You’ve got a couple of problems there:

    1) the first part of conditions, “id != ?”, is a fragment of sql, and in sql you do “not equals” as <> not !=. Eg "id <> ?"

    2) To use an array, the sql syntax is id in (1,2,3) or id not in (1,2,3). In your conditions you can do this like :conditions => ["id not in (?)", array_of_ids]

    So, you could get players not on a team like this:

    @team = Team.find(params[:team_id])
    @not_on_team = Player.find(:all, :conditions => ["id not in (?)", @team.player_ids])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models defined: class Player(models.Model): Team = models.ForeignKey(Team) Name = models.CharField(max_length=200)
My models class Team < ActiveRecord::Base has_many :team_players has_many :players, :through => :team_players end
i have the following models setup class Player(models.Model): #slug = models.slugField(max_length=200) Player_Name = models.CharField(max_length=100)
I have three models: class ReleaseItem < ActiveRecord::Base has_many :pack_release_items has_one :pack, :through =>
I currently have the following models: class Player < ActiveRecord::Base belongs_to :team belongs_to :user
I have the following models: class Fixture(models.Model): id = models.AutoField(primary_key=True) home_team = models.ForeignKey(Player, related_name=home)
Let's imagine we have two models: Teams: Id, Name Player: Id, Name, TeamId I
Imagine you have two entities, Player and Team , where players can be on
I have a django model like this: class Player(models.Model): name = models.CharField() batting =
I have a player, game, shot, round and team model. When creating a shot,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.