meta_where 0.9.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGELOG +3 -0
  2. data/README.rdoc +41 -0
  3. data/VERSION +1 -1
  4. data/meta_where.gemspec +2 -2
  5. metadata +4 -4
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ Changes since 0.9.10 (2011-01-06):
2
+ * Doc updates only, and a version change to 1.0.0.
3
+
1
4
  Changes since 0.9.9 (2010-11-15):
2
5
  * Multiple conditions on the same column with the same predicate will be "OR"ed
3
6
  instead of dropping all but the last one. This tracks the same behavior in
@@ -283,6 +283,47 @@ mapping," above) and also some convenience methods for ascending and descending
283
283
  ORDER BY "articles"."title" DESC,
284
284
  "comments"."created_at" ASC, "comments"."updated_at"
285
285
 
286
+ == Polymorphic belongs_to joins
287
+
288
+ Polymorphic associations provide great flexibility, but they can sometimes be a bit of a hassle
289
+ when it comes to querying through a belongs_to association. First, you have to know what type
290
+ you're looking for to do a proper join, and then, you're forced into using a string join in order
291
+ to make it happen (which would prevent the use of MetaWhere intelligent condition mapping).
292
+
293
+ MetaWhere allows you to join polymorphic belongs_to associations like this:
294
+
295
+ Note.joins(:notable.type(Developer)).
296
+ where(:notable.type(Developer) => {:name.matches => 'Ernie%'})
297
+ => SELECT "notes".* FROM "notes"
298
+ INNER JOIN "developers" ON "developers"."id" = "notes"."notable_id"
299
+ AND "notes"."notable_type" = 'Developer'
300
+ WHERE "developers"."name" LIKE 'Ernie%'
301
+
302
+ == Using ActiveRecord objects as condition values
303
+
304
+ Wouldn't it be nice if you could do something like this?
305
+
306
+ # Developer belongs_to Company
307
+ company = Company.find(123)
308
+ Developer.where(:company => company)
309
+
310
+ # Developer HABTM Projects
311
+ projects = [Project.first, Project.last]
312
+ Developer.joins(:projects).where(:projects => projects)
313
+
314
+ # Note belongs_to :notable, :polymorphic => true
315
+ dev1 = Developer.first
316
+ dev2 = Developer.last
317
+ project = Project.first
318
+ company = Company.first
319
+ Note.where(:notable => [dev1, dev2, project, company]).to_sql
320
+ => SELECT "notes".* FROM "notes" WHERE (((("notes"."notable_id" IN (1, 8)
321
+ AND "notes"."notable_type" = 'Developer') OR ("notes"."notable_id" = 1
322
+ AND "notes"."notable_type" = 'Project')) OR ("notes"."notable_id" = 1
323
+ AND "notes"."notable_type" = 'Company')))
324
+
325
+ With MetaWhere, you can.
326
+
286
327
  == Thanks
287
328
  A huge thank you goes to Pratik Naik (lifo) for a dicussion on #rails-contrib about a patch
288
329
  I'd submitted, and his take on a DSL for query conditions, which was the inspiration for this
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.10
1
+ 1.0.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{meta_where}
8
- s.version = "0.9.10"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ernie Miller"]
12
- s.date = %q{2011-01-06}
12
+ s.date = %q{2011-01-17}
13
13
  s.description = %q{
14
14
  MetaWhere offers the ability to call any Arel predicate methods
15
15
  (with a few convenient aliases) on your Model's attributes instead
metadata CHANGED
@@ -3,10 +3,10 @@ name: meta_where
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
- - 9
8
- - 10
9
- version: 0.9.10
8
+ - 0
9
+ version: 1.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ernie Miller
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-06 00:00:00 -05:00
17
+ date: 2011-01-17 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency