...I get several roles with the same ID and NAME, but I want to get
unique ones, like using DISTINCT operation in SQL statements (SELECT
DISTINCT name FROM roles.....)
But unfortunately I can get the list from table "members", where records
may have several same role names:
If you want a list of roles, why would you go through the members
table to get it? You can just do Roles.find(:all).map(&:name)
I'm not sure what you doing with "assignable?". It seems to be
important to you, but you have not explained what it is supposed to
return.
What does it do? Does it return:
a) members who do not have a role and are therefore able to be
assigned a role ?
b) some awkward pass-through delegation to roles that aren't assigned yet ?
"assignable?" is just a filter to select roles that have attribute
"assignable" set to true.
Regarding roles... I want to select not all roles, but roles that are
members of project. And also I cannot change database structure. So I
have the following entities relations:
Roles <- Members -> Projects
>
\ /
Users
Unfortunately I don't know how to select (using RoR) unique roles that
regard only defined project.
In SQL it looks like:
SELECT Roles.id, Roles.name
FROM Roles, Members
WHERE Members.project_id=5