Noob question about object arrays

I hope this is not too much of a newbie question. I have been looking for posts and haven't found anything yet, so I thought I would try the forum for the first time.

I am a developer at a school district creating a Rails app for scheduling some Intervention classes. I am trying to create a drop-down list of students who are not yet enrolled by subtracting an array of enrolled student numbers from an array of all student numbers. Something like this:

available_students = all_students - enrolled_students

I am getting all_students as the result, and I am assuming it is because the arrays are of different types. The all_students array looks like this in the console:

Because everything about enrollments is in the enrollments table, not the students table.

But there should be a relationship between the students and the enrollments table isn't there? Can you show us the students and enrollments models? I'm going off the cuff since I don't know your system but each enrollment should belong to a student and a student has_many enrollments?

I don't know if 'array subtraction' works in ruby but a solution would be to loop through the all students array, check if they are in the enrolled array and if they aren't push them to the available_students array.

all_students.each do |student|

available_student.push(student) unless student is already in the enrolled student array

Jemagee has a point. Your database doesn't seem to be modelled properly

A student should have an enrolled flag rather than a seperate enrolled table. This is a case for de-normalisation.

If you want to have a sperate table then set up a relationship between the two. i.e. include a foreign key from the students table in the enrolled table.

Maybe this is what you already have?

Well - that all depends on if we are only talking about intervention courses or all courses - if you're designing an enrollment model for a school your going to have a students table and courses table and an enrollment 'cross join' (that's the SQL term for it) table that contains the course ID and student ID

Have I mentioned that I love data - i love normalizing it - i love querying against it (i still remember my most favorite query that queried the same table 3 times with 2 aliases to work properly - loved seeing it work) so if any one has any normalization questions - i'd be happy to help

Just to clarify, I do have multiple tables set up (in a similar way to our school information system) much the way you have described. I think I wasn't very clear in my first question and description of the problem. The problem I was having was in not knowing how to properly use the .map or .collect, which james has clarified in his answer. I think this will get me going. If not, I'll be back with more questions....

Good question - turns out i love databases - even before I knew what 'relational databases' were with my commodore 64 and then apple 2gs i was building databases to track my comic book collection (but I was doing it improperly it turns out) Databases are fun, making data my bitch gives me great joy - got some data you don't wanna futz with but need to - send it my way