diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2012-04-18 00:10:06 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2012-04-18 00:10:06 +0530 |
commit | 5b336ff44364ac4adcf137838e71a8f0bb4f35a0 (patch) | |
tree | c15002d3b3a2a5c2a2f8c17c309f170620025408 /guides/source | |
parent | 1d26fcb9f896a3dc98d90ad734aa5da7ac2bbcda (diff) | |
parent | b7e3c8e1f387e4c0843371971317ca7972d8aeb5 (diff) | |
download | rails-5b336ff44364ac4adcf137838e71a8f0bb4f35a0.tar.gz rails-5b336ff44364ac4adcf137838e71a8f0bb4f35a0.tar.bz2 rails-5b336ff44364ac4adcf137838e71a8f0bb4f35a0.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/active_record_querying.textile | 11 | ||||
-rw-r--r-- | guides/source/migrations.textile | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/guides/source/active_record_querying.textile b/guides/source/active_record_querying.textile index de55401c1f..58eae2ee0f 100644 --- a/guides/source/active_record_querying.textile +++ b/guides/source/active_record_querying.textile @@ -539,7 +539,9 @@ And this will give you a single +Order+ object for each date where there are ord The SQL that would be executed would be something like this: <sql> -SELECT date(created_at) as ordered_date, sum(price) as total_price FROM orders GROUP BY date(created_at) +SELECT date(created_at) as ordered_date, sum(price) as total_price +FROM orders +GROUP BY date(created_at) </sql> h3. Having @@ -555,7 +557,10 @@ Order.select("date(created_at) as ordered_date, sum(price) as total_price").grou The SQL that would be executed would be something like this: <sql> -SELECT date(created_at) as ordered_date, sum(price) as total_price FROM orders GROUP BY date(created_at) HAVING sum(price) > 100 +SELECT date(created_at) as ordered_date, sum(price) as total_price +FROM orders +GROUP BY date(created_at) +HAVING sum(price) > 100 </sql> This will return single order objects for each day, but only those that are ordered more than $100 in a day. @@ -829,7 +834,7 @@ SELECT categories.* FROM categories INNER JOIN posts ON posts.category_id = categories.id </sql> -Or, in English: "return a Category object for all categories with posts". Note that you will see duplicate categories if more than one post has the same category. If you want unique categories, you can use Category.joins(:post).select("distinct(categories.id)"). +Or, in English: "return a Category object for all categories with posts". Note that you will see duplicate categories if more than one post has the same category. If you want unique categories, you can use Category.joins(:posts).select("distinct(categories.id)"). h5. Joining Multiple Associations diff --git a/guides/source/migrations.textile b/guides/source/migrations.textile index aa75e9ab4a..1eeb27f3c1 100644 --- a/guides/source/migrations.textile +++ b/guides/source/migrations.textile @@ -779,7 +779,7 @@ Both migrations work for Alice. Bob comes back from vacation and: -# Updates the source - which contains both migrations and the latests version of +# Updates the source - which contains both migrations and the latest version of the Product model. # Runs outstanding migrations with +rake db:migrate+, which includes the one that updates the +Product+ model. |