Created
August 22, 2012 11:49
-
-
Save anonymous/3424786 to your computer and use it in GitHub Desktop.
Problem finding in a collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
#Connecting with SFDC | |
config = YAML.load_file(File.join(::Rails.root, 'config', 'databasedotcom.yml')) | |
client = Databasedotcom::Client.new(config) | |
client.authenticate :username => config[:username], :password => config[:password] | |
#Get a collection of Solutions and stored in a var visible for all the methods | |
@@sols = client.query("SELECT Soluci_n_Hija__r.Id, | |
Soluci_n_Hija__r.SolutionName, | |
Soluci_n_Hija__r.NumeroVisitas__c, | |
Soluci_n_Hija__r.Contenido__c, | |
Soluci_n_Hija__r.Tipo__c, | |
Soluci_n_Padre__r.Id | |
FROM Solution_Rel__c | |
where Soluci_n_Hija__r.RecordTypeId='012D0000000BBCQ'") | |
#Find the top 3 solutions more visited | |
@masvisitadas= @@sols.sort_by{|s| -s.Soluci_n_Hija__r.NumeroVisitas__c}[0..2] | |
#Find solutions of first level in the tree, his parent.Id is the parent of all solutions | |
@listasol=@@sols.find{|a| a.Soluci_n_Padre__r.Id == '50120000000bF8fAAE' } | |
#Find the solutions of the second level, any that have a parent in listasol | |
@listasollvl=@@sols.find{|a| a.Soluci_n_Padre__r.Id in [@listasol.Soluci_n_Hija__r.Id]} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment