J
Jarrett Green
This is a pretty ugly hash. The keys are objects. I'm afraid after going
down a few paths, it was a bit over my head. Here's the hash:
[[#<Company id: 13, name: "Company Test 1", created_at: "2008-09-03
04:05:58", updated_at: "2008-09-03 04:05:58", account_id: 16,
account_company: false>, [#<Project id: 34, name: "Test", created_at:
"2008-09-07 04:54:55", updated_at: "2008-09-07 04:54:55", account_id:
16, primary_company_id: 13>]], [#<Company id: 12, name: "Company Test
2", created_at: "................
Yeah. I know..
So briefly, the keys look like is #<Company id: 13, name: "Company Test
1", ..... >.
I need to sort by 'name'. Though another question remains that would
make this all moot. I use:
@project_companies = @projects.group_by(&rimary_company)
where rimary_company is a relationship situation. I found I can use
either the foreign key, primary_company_id, which would just give me
the id), or the above which gives me the whole enitre object as a key.
But is there any in between? Something like:
@project_companies = @projects.group_by(&rimary_company.name)
If not, how can I create my own sort using <=>??? I found a bit in the
rdoc, and well now I'm here.
down a few paths, it was a bit over my head. Here's the hash:
[[#<Company id: 13, name: "Company Test 1", created_at: "2008-09-03
04:05:58", updated_at: "2008-09-03 04:05:58", account_id: 16,
account_company: false>, [#<Project id: 34, name: "Test", created_at:
"2008-09-07 04:54:55", updated_at: "2008-09-07 04:54:55", account_id:
16, primary_company_id: 13>]], [#<Company id: 12, name: "Company Test
2", created_at: "................
Yeah. I know..
So briefly, the keys look like is #<Company id: 13, name: "Company Test
1", ..... >.
I need to sort by 'name'. Though another question remains that would
make this all moot. I use:
@project_companies = @projects.group_by(&rimary_company)
where rimary_company is a relationship situation. I found I can use
either the foreign key, primary_company_id, which would just give me
the id), or the above which gives me the whole enitre object as a key.
But is there any in between? Something like:
@project_companies = @projects.group_by(&rimary_company.name)
If not, how can I create my own sort using <=>??? I found a bit in the
rdoc, and well now I'm here.