Tous les enregistrements par tri croissant tab = User.find :all, :order=>"name asc"
On peut utiliser les fonctions find_by_xxxxxx pour un enregistrement et find_all_by où xxxxxx correspond au nom du champ de la table : u = User.find_by_name("DUPONT") <=> u = User.find :first, :conditions=>"name = 'DUPONT'"
tab = User.find_all_by_name("DUPONT") <=> tab = User.find :all, :conditions=>"name = 'DUPONT'"
on peut conbiner (and seulement fonctionne pour l'instant -> tester pour or) tab = User.find_all_by_name_and_prenom("DUPONT", "PIERRE")
les recherches sont très lisibles
Tester le résultat d'une recherche : tab = User.find_all_by_name("DUPONT") if !tab.empty? # find_all retourne un tableau end
tab = User.find_by_name("DUPONT")
if !tab.nil?
# find retourne un enregistrement ou null si rien
end
|