Wednesday 15 May 2013

Get Unique contents from Ruby Hash -


I have hash @satellite:

  [# & lt; Property ID: 1, Name: "Thane", Address: "Thane St.", Created: "2013-06-21 16:40:50", updated_t: "2013-06-21 16:40:50", User_ID: 2, asset_file_name: "DSC02358.JPG", asset_content_type: "image / jpeg", asset_file_size: 5520613, asset_updated_at: "2013-06-21 16:40:49", MGMT: "ABC">, # more lieutenant; Estate ID: 2, Name: "Mumbai", Address: "Mumbai St.", created_aut: "2013-06-21 19:13:59", updated_at: "2013-06-21 19:14:28", user_id : 2, asset_file_name: "DSC02359.JPG", asset_content_type: "image / jpeg", asset_file_size: 5085580, asset_updated_at: "2013-06-21 19:13:57", MGMT: "ABC">]]   

According to the user_id: 2 , it is possible to create a new hash with unique values ​​because currently 2 elements are user_id i.e. 2, i just have it once in hash I want to do, what should I do?

It looks like has_many user model And the relationship between estate model, right? If you really believe that you are right, then your estate by user_id :

PostgreSQL:

  property. Selection ('separate on' (user_id * *) All   

MySQL:

  Estate.group (: user_id) .all   

Do not advise to select archives and then handle them with data in a more efficient manner as a process with Ruby.

No comments:

Post a Comment