Ruby On Rails in UA Icon_home Главная Add to bookmarks Translate translate Profile Войти
Регистрация Форум Блоги Пользователи Список джемов Rails проекты      Поиск   

Ruby On Rails in UA/Программирование на ROR/Следующая запись/RE: RE: RE: Следующая запись

2008-06-05 09:05:01 Ответить  
admin
Ruslan Voloshin
Адрес: odessa
Сообщений: 1296
Регистр: 2007-03-13
его блог 40 сообщ.
RE: RE: RE: Следующая запись
  •  
В описании API по Active Record есть куча ключей которые ты можешь использовать думаю елси ты посомтришь туда тогда тебе станет все понятно сразу

find(*args)

Примеры поиска при различных типахх запросов:

* Find by id: This can either be a specific id (1), a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]). If no record can be found for all of the listed ids, then RecordNotFound will be raised.
* Find first: This will return the first record matched by the options used. These options can either be specific conditions or merely an order. If no record can matched, nil is returned.
* Find all: This will return all the records matched by the options used. If no records are found, an empty array is returned.

All approaches accept an option hash as their last parameter. The options are:

* :conditions: An SQL fragment like "administrator = 1" or [ "user_name = ?", username ]. See conditions in the intro.
* :order: An SQL fragment like "created_at DESC, name".
* :group: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause.
* :limit: An integer determining the limit on the number of rows that should be returned.
* :offset: An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
* :joins: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id". (Rarely needed). The records will be returned read-only since they will have attributes that do not correspond to the table’s columns. Pass :readonly => false to override.
* :include: Names associations that should be loaded alongside using LEFT OUTER JOINs. The symbols named refer to already defined associations. See eager loading under Associations.
* :select: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not include the joined columns.
* :readonly: Mark the returned records read-only so they cannot be saved or updated.

Примеры поиска по id:


Примеры поиска для first:

Примеры поиска для all:

------------
Занимаюсь вебом и продвижением сайтов.
Назадназад Новыйновый Ответитьответить
Ключевые слова:
Гости: 81 Онлайн: 0
Rambler's Top100
О проекте по всем вопросам обращайтесь на support
Rubyclub.com.ua Copyright © 2007 - 2008