postgres_tree 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 302debd5eb94f2d153549003f9e2bd9c90af4094
4
- data.tar.gz: f8beb3a9ab10714e909466eb96e205c2e9554252
3
+ metadata.gz: 483400384d001e4d4a7cb01a5d77f22ef18d70a7
4
+ data.tar.gz: bb55d1b2321d1a4a25c7a15ca8291ebe8e6492bb
5
5
  SHA512:
6
- metadata.gz: 0b7e754f9d090674e39788b12998ea5d69d9d558b8315027161618aea55db0c63777d9297f2b8ceb8f5694e1087e7ebc534658a7bb1a2bf3e544100142288094
7
- data.tar.gz: 738c71fe241fcc5770b2ddcac5b0842b720e62bbe9c7ef7336e8336308bed886e74f7aece51ebc705781ce28819f0beee9e94d118c39357cb2fd4572ac68f394
6
+ metadata.gz: 2f53208c74944cdb1ea47507c853eaf373c8e9915bb69cd2dfd887ea2855f06655c94953bc385796b344521d931bf1644e9b0670a9e3f86190195c9af446bd16
7
+ data.tar.gz: 305257082f0bd368c7238a00989c3e17cd8b9020fe22fe876f5304ebace8e29e1d7d5a68402b19b58f8fa99dbf4ef6b1c69d3c48b106fc2f8cd2720fd51d20f4
@@ -8,33 +8,56 @@ module PostgresTree::ActiveRecordConcern
8
8
  scope :tree_roots, -> { where(parent_id: nil) }
9
9
  end
10
10
 
11
- # Ancestors
11
+ # Get all ancestors
12
+ #
13
+ # Example:
14
+ # > parent.ancestors
15
+ # => [#<Role id: 1, name: "Grandparent", parent_id: nil>]
16
+
12
17
  def ancestors
13
18
  self_and_ancestors - [self]
14
19
  end
20
+
21
+ # Get all ancestors and include self in the returned result
22
+ #
23
+ # Example:
24
+ # > parent.self_and_ancestors
25
+ # => #<ActiveRecord::Relation [#<Role id: 1, name: "Grandparent", parent_id: nil>, #<Role id: 2, name: "Parent", parent_id: 1>]>
26
+
15
27
  def self_and_ancestors
16
28
  self_and_ancestors_for(self)
17
29
  end
18
30
 
19
- # Descendents
31
+ # Get all descendents
32
+ #
33
+ # Example:
34
+ # > parent.descendents
35
+ # => [#<Role id: 3, name: "Child", parent_id: 2>]
36
+
20
37
  def descendents
21
38
  self_and_descendents - [self]
22
39
  end
40
+
41
+ # Get all descendents and include self in the returned result
42
+ #
43
+ # Example:
44
+ # > parent.self_and_descendents
45
+ # => #<ActiveRecord::Relation [#<Role id: 2, name: "Parent", parent_id: 1>, #<Role id: 3, name: "Child", parent_id: 2>]>
46
+
23
47
  def self_and_descendents
24
48
  self_and_descendents_for(self)
25
49
  end
26
50
 
27
- # Check if ancestors, self_and_ancestors, descendents or self_and_descendents includes? object
28
- def method_missing(method, *args, &block)
29
- if method.to_s =~ /\A(.+)_include\?\z/
30
- self.send($1.to_sym).include? *args.first
31
- else
32
- super
33
- end
34
- end
35
-
36
51
  private
37
52
 
53
+ def method_missing(method, *args, &block)
54
+ if method.to_s =~ /\A(.+)_include\?\z/
55
+ self.send($1.to_sym).include? *args.first
56
+ else
57
+ super
58
+ end
59
+ end
60
+
38
61
  def respond_to_missing?(method, include_private_methods = false)
39
62
  method.to_s =~ /\A(.+)_include\?\z/ || super
40
63
  end
@@ -1,3 +1,3 @@
1
1
  module PostgresTree
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -3231,3 +3231,487 @@ PersonTest: test_tree_roots_scope
3231
3231
  PostgresTreeTest: test_truth
3232
3232
  ----------------------------
3233
3233
   (0.1ms) ROLLBACK
3234
+ ActiveRecord::SchemaMigration Load (26.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
3235
+  (221.9ms) drop schema public cascade;
3236
+  (49.0ms) create schema public;
3237
+  (150.1ms) CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL)
3238
+  (108.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3239
+ ActiveRecord::SchemaMigration Load (0.7ms) SELECT "schema_migrations".* FROM "schema_migrations"
3240
+ Migrating to CreatePeople (20140918023556)
3241
+  (0.1ms) BEGIN
3242
+  (128.8ms) CREATE TABLE "people" ("id" serial primary key, "name" character varying(255), "parent_id" integer, "created_at" timestamp, "updated_at" timestamp)
3243
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20140918023556"]]
3244
+  (19.5ms) COMMIT
3245
+  (37.8ms) ALTER TABLE "schema_migrations" DISABLE TRIGGER ALL;ALTER TABLE "people" DISABLE TRIGGER ALL
3246
+  (0.5ms) BEGIN
3247
+ Fixture Delete (0.8ms) DELETE FROM "people"
3248
+ Fixture Insert (0.6ms) INSERT INTO "people" ("id", "name", "created_at", "updated_at") VALUES (1, 'Grandad', '2014-09-22 05:30:23', '2014-09-22 05:30:23')
3249
+ Fixture Insert (0.3ms) INSERT INTO "people" ("id", "name", "parent_id", "created_at", "updated_at") VALUES (2, 'Dad', 1, '2014-09-22 05:30:23', '2014-09-22 05:30:23')
3250
+ Fixture Insert (0.2ms) INSERT INTO "people" ("id", "name", "parent_id", "created_at", "updated_at") VALUES (3, 'Son', 2, '2014-09-22 05:30:23', '2014-09-22 05:30:23')
3251
+  (55.4ms) COMMIT
3252
+  (0.2ms) ALTER TABLE "schema_migrations" ENABLE TRIGGER ALL;ALTER TABLE "people" ENABLE TRIGGER ALL
3253
+  (0.1ms) BEGIN
3254
+ ------------------------------
3255
+ PersonTest: test_dad_ancestors
3256
+ ------------------------------
3257
+ Person Load (0.4ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 1]]
3258
+ Person Load (0.5ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 2]]
3259
+ Person Load (2.1ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3260
+ SELECT id, parent_id, ARRAY[id]
3261
+ FROM people
3262
+ WHERE id = 2
3263
+ UNION ALL
3264
+ SELECT people.id, people.parent_id, path || people.id
3265
+ FROM search_tree
3266
+ JOIN people ON people.id = search_tree.parent_id
3267
+ WHERE NOT people.id = ANY(path)
3268
+ )
3269
+ SELECT id FROM search_tree ORDER BY path DESC
3270
+ ))
3271
+ Person Load (0.8ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3272
+ SELECT id, parent_id, ARRAY[id]
3273
+ FROM people
3274
+ WHERE id = 2
3275
+ UNION ALL
3276
+ SELECT people.id, people.parent_id, path || people.id
3277
+ FROM search_tree
3278
+ JOIN people ON people.id = search_tree.parent_id
3279
+ WHERE NOT people.id = ANY(path)
3280
+ )
3281
+ SELECT id FROM search_tree ORDER BY path DESC
3282
+ ))
3283
+  (1.0ms) SELECT COUNT(*) FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3284
+ SELECT id, parent_id, ARRAY[id]
3285
+ FROM people
3286
+ WHERE id = 2
3287
+ UNION ALL
3288
+ SELECT people.id, people.parent_id, path || people.id
3289
+ FROM search_tree
3290
+ JOIN people ON people.id = search_tree.parent_id
3291
+ WHERE NOT people.id = ANY(path)
3292
+ )
3293
+ SELECT id FROM search_tree ORDER BY path DESC
3294
+ ))
3295
+ Person Load (1.1ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3296
+ SELECT id, parent_id, ARRAY[id]
3297
+ FROM people
3298
+ WHERE id = 2
3299
+ UNION ALL
3300
+ SELECT people.id, people.parent_id, path || people.id
3301
+ FROM search_tree
3302
+ JOIN people ON people.id = search_tree.parent_id
3303
+ WHERE NOT people.id = ANY(path)
3304
+ )
3305
+ SELECT id FROM search_tree ORDER BY path DESC
3306
+ ))
3307
+ Person Load (0.9ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3308
+ SELECT id, parent_id, ARRAY[id]
3309
+ FROM people
3310
+ WHERE id = 2
3311
+ UNION ALL
3312
+ SELECT people.id, people.parent_id, path || people.id
3313
+ FROM search_tree
3314
+ JOIN people ON people.id = search_tree.parent_id
3315
+ WHERE NOT people.id = ANY(path)
3316
+ )
3317
+ SELECT id FROM search_tree ORDER BY path DESC
3318
+ ))
3319
+ Person Load (1.6ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3320
+ SELECT id, parent_id, ARRAY[id]
3321
+ FROM people
3322
+ WHERE id = 2
3323
+ UNION ALL
3324
+ SELECT people.id, people.parent_id, path || people.id
3325
+ FROM search_tree
3326
+ JOIN people ON people.id = search_tree.parent_id
3327
+ WHERE NOT people.id = ANY(path)
3328
+ )
3329
+ SELECT id FROM search_tree ORDER BY path DESC
3330
+ ))
3331
+  (0.2ms) ROLLBACK
3332
+  (0.1ms) BEGIN
3333
+ --------------------------------
3334
+ PersonTest: test_dad_descendents
3335
+ --------------------------------
3336
+ Person Load (0.2ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 2]]
3337
+ Person Load (0.3ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 3]]
3338
+ Person Load (0.6ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3339
+ SELECT id, ARRAY[id]
3340
+ FROM people
3341
+ WHERE id = 2
3342
+ UNION ALL
3343
+ SELECT people.id, path || people.id
3344
+ FROM search_tree
3345
+ JOIN people ON people.parent_id = search_tree.id
3346
+ WHERE NOT people.id = ANY(path)
3347
+ )
3348
+ SELECT id FROM search_tree ORDER BY path
3349
+ ))
3350
+ Person Load (0.5ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3351
+ SELECT id, ARRAY[id]
3352
+ FROM people
3353
+ WHERE id = 2
3354
+ UNION ALL
3355
+ SELECT people.id, path || people.id
3356
+ FROM search_tree
3357
+ JOIN people ON people.parent_id = search_tree.id
3358
+ WHERE NOT people.id = ANY(path)
3359
+ )
3360
+ SELECT id FROM search_tree ORDER BY path
3361
+ ))
3362
+  (0.5ms) SELECT COUNT(*) FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3363
+ SELECT id, ARRAY[id]
3364
+ FROM people
3365
+ WHERE id = 2
3366
+ UNION ALL
3367
+ SELECT people.id, path || people.id
3368
+ FROM search_tree
3369
+ JOIN people ON people.parent_id = search_tree.id
3370
+ WHERE NOT people.id = ANY(path)
3371
+ )
3372
+ SELECT id FROM search_tree ORDER BY path
3373
+ ))
3374
+ Person Load (0.5ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3375
+ SELECT id, ARRAY[id]
3376
+ FROM people
3377
+ WHERE id = 2
3378
+ UNION ALL
3379
+ SELECT people.id, path || people.id
3380
+ FROM search_tree
3381
+ JOIN people ON people.parent_id = search_tree.id
3382
+ WHERE NOT people.id = ANY(path)
3383
+ )
3384
+ SELECT id FROM search_tree ORDER BY path
3385
+ ))
3386
+ Person Load (0.7ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3387
+ SELECT id, ARRAY[id]
3388
+ FROM people
3389
+ WHERE id = 2
3390
+ UNION ALL
3391
+ SELECT people.id, path || people.id
3392
+ FROM search_tree
3393
+ JOIN people ON people.parent_id = search_tree.id
3394
+ WHERE NOT people.id = ANY(path)
3395
+ )
3396
+ SELECT id FROM search_tree ORDER BY path
3397
+ ))
3398
+ Person Load (0.8ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3399
+ SELECT id, ARRAY[id]
3400
+ FROM people
3401
+ WHERE id = 2
3402
+ UNION ALL
3403
+ SELECT people.id, path || people.id
3404
+ FROM search_tree
3405
+ JOIN people ON people.parent_id = search_tree.id
3406
+ WHERE NOT people.id = ANY(path)
3407
+ )
3408
+ SELECT id FROM search_tree ORDER BY path
3409
+ ))
3410
+  (0.2ms) ROLLBACK
3411
+  (0.1ms) BEGIN
3412
+ ----------------------------------
3413
+ PersonTest: test_grandad_ancestors
3414
+ ----------------------------------
3415
+ Person Load (0.3ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 1]]
3416
+ Person Load (0.8ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3417
+ SELECT id, parent_id, ARRAY[id]
3418
+ FROM people
3419
+ WHERE id = 1
3420
+ UNION ALL
3421
+ SELECT people.id, people.parent_id, path || people.id
3422
+ FROM search_tree
3423
+ JOIN people ON people.id = search_tree.parent_id
3424
+ WHERE NOT people.id = ANY(path)
3425
+ )
3426
+ SELECT id FROM search_tree ORDER BY path DESC
3427
+ ))
3428
+  (0.1ms) ROLLBACK
3429
+  (0.1ms) BEGIN
3430
+ ---------------------------------------
3431
+ PersonTest: test_person_fixtures_loaded
3432
+ ---------------------------------------
3433
+ Person Load (0.4ms) SELECT "people".* FROM "people" ORDER BY "people"."id" ASC LIMIT 1
3434
+  (0.2ms) ROLLBACK
3435
+  (0.1ms) BEGIN
3436
+ ---------------------------------------------
3437
+ PersonTest: test_respond_to_all_magic_methods
3438
+ ---------------------------------------------
3439
+ Person Load (0.4ms) SELECT "people".* FROM "people" ORDER BY "people"."id" ASC LIMIT 1
3440
+  (0.2ms) ROLLBACK
3441
+  (0.1ms) BEGIN
3442
+ ----------------------------------------
3443
+ PersonTest: test_responds_to_all_methods
3444
+ ----------------------------------------
3445
+ Person Load (0.2ms) SELECT "people".* FROM "people" ORDER BY "people"."id" ASC LIMIT 1
3446
+  (0.1ms) ROLLBACK
3447
+  (0.1ms) BEGIN
3448
+ --------------------------------
3449
+ PersonTest: test_son_descendents
3450
+ --------------------------------
3451
+ Person Load (0.4ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 3]]
3452
+ Person Load (0.7ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3453
+ SELECT id, ARRAY[id]
3454
+ FROM people
3455
+ WHERE id = 3
3456
+ UNION ALL
3457
+ SELECT people.id, path || people.id
3458
+ FROM search_tree
3459
+ JOIN people ON people.parent_id = search_tree.id
3460
+ WHERE NOT people.id = ANY(path)
3461
+ )
3462
+ SELECT id FROM search_tree ORDER BY path
3463
+ ))
3464
+  (0.1ms) ROLLBACK
3465
+  (0.1ms) BEGIN
3466
+ ---------------------------------
3467
+ PersonTest: test_tree_roots_scope
3468
+ ---------------------------------
3469
+  (0.4ms) SELECT COUNT(*) FROM "people" WHERE "people"."parent_id" IS NULL
3470
+  (0.1ms) ROLLBACK
3471
+  (0.1ms) BEGIN
3472
+ ----------------------------
3473
+ PostgresTreeTest: test_truth
3474
+ ----------------------------
3475
+  (0.1ms) ROLLBACK
3476
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
3477
+  (46.4ms) drop schema public cascade;
3478
+  (7.1ms) create schema public;
3479
+  (8.1ms) CREATE TABLE "schema_migrations" ("version" character varying(255) NOT NULL)
3480
+  (64.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3481
+ ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
3482
+ Migrating to CreatePeople (20140918023556)
3483
+  (0.2ms) BEGIN
3484
+  (60.8ms) CREATE TABLE "people" ("id" serial primary key, "name" character varying(255), "parent_id" integer, "created_at" timestamp, "updated_at" timestamp)
3485
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20140918023556"]]
3486
+  (19.4ms) COMMIT
3487
+  (0.5ms) ALTER TABLE "schema_migrations" DISABLE TRIGGER ALL;ALTER TABLE "people" DISABLE TRIGGER ALL
3488
+  (0.7ms) BEGIN
3489
+ Fixture Delete (0.3ms) DELETE FROM "people"
3490
+ Fixture Insert (0.4ms) INSERT INTO "people" ("id", "name", "created_at", "updated_at") VALUES (1, 'Grandad', '2014-09-22 05:40:02', '2014-09-22 05:40:02')
3491
+ Fixture Insert (0.2ms) INSERT INTO "people" ("id", "name", "parent_id", "created_at", "updated_at") VALUES (2, 'Dad', 1, '2014-09-22 05:40:02', '2014-09-22 05:40:02')
3492
+ Fixture Insert (0.2ms) INSERT INTO "people" ("id", "name", "parent_id", "created_at", "updated_at") VALUES (3, 'Son', 2, '2014-09-22 05:40:02', '2014-09-22 05:40:02')
3493
+  (10.4ms) COMMIT
3494
+  (0.2ms) ALTER TABLE "schema_migrations" ENABLE TRIGGER ALL;ALTER TABLE "people" ENABLE TRIGGER ALL
3495
+  (0.2ms) BEGIN
3496
+ ----------------------------
3497
+ PostgresTreeTest: test_truth
3498
+ ----------------------------
3499
+  (0.2ms) ROLLBACK
3500
+  (0.1ms) BEGIN
3501
+ ------------------------------
3502
+ PersonTest: test_dad_ancestors
3503
+ ------------------------------
3504
+ Person Load (0.4ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 1]]
3505
+ Person Load (0.3ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 2]]
3506
+ Person Load (1.0ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3507
+ SELECT id, parent_id, ARRAY[id]
3508
+ FROM people
3509
+ WHERE id = 2
3510
+ UNION ALL
3511
+ SELECT people.id, people.parent_id, path || people.id
3512
+ FROM search_tree
3513
+ JOIN people ON people.id = search_tree.parent_id
3514
+ WHERE NOT people.id = ANY(path)
3515
+ )
3516
+ SELECT id FROM search_tree ORDER BY path DESC
3517
+ ))
3518
+ Person Load (0.5ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3519
+ SELECT id, parent_id, ARRAY[id]
3520
+ FROM people
3521
+ WHERE id = 2
3522
+ UNION ALL
3523
+ SELECT people.id, people.parent_id, path || people.id
3524
+ FROM search_tree
3525
+ JOIN people ON people.id = search_tree.parent_id
3526
+ WHERE NOT people.id = ANY(path)
3527
+ )
3528
+ SELECT id FROM search_tree ORDER BY path DESC
3529
+ ))
3530
+  (0.8ms) SELECT COUNT(*) FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3531
+ SELECT id, parent_id, ARRAY[id]
3532
+ FROM people
3533
+ WHERE id = 2
3534
+ UNION ALL
3535
+ SELECT people.id, people.parent_id, path || people.id
3536
+ FROM search_tree
3537
+ JOIN people ON people.id = search_tree.parent_id
3538
+ WHERE NOT people.id = ANY(path)
3539
+ )
3540
+ SELECT id FROM search_tree ORDER BY path DESC
3541
+ ))
3542
+ Person Load (0.7ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3543
+ SELECT id, parent_id, ARRAY[id]
3544
+ FROM people
3545
+ WHERE id = 2
3546
+ UNION ALL
3547
+ SELECT people.id, people.parent_id, path || people.id
3548
+ FROM search_tree
3549
+ JOIN people ON people.id = search_tree.parent_id
3550
+ WHERE NOT people.id = ANY(path)
3551
+ )
3552
+ SELECT id FROM search_tree ORDER BY path DESC
3553
+ ))
3554
+ Person Load (1.3ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3555
+ SELECT id, parent_id, ARRAY[id]
3556
+ FROM people
3557
+ WHERE id = 2
3558
+ UNION ALL
3559
+ SELECT people.id, people.parent_id, path || people.id
3560
+ FROM search_tree
3561
+ JOIN people ON people.id = search_tree.parent_id
3562
+ WHERE NOT people.id = ANY(path)
3563
+ )
3564
+ SELECT id FROM search_tree ORDER BY path DESC
3565
+ ))
3566
+ Person Load (1.1ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3567
+ SELECT id, parent_id, ARRAY[id]
3568
+ FROM people
3569
+ WHERE id = 2
3570
+ UNION ALL
3571
+ SELECT people.id, people.parent_id, path || people.id
3572
+ FROM search_tree
3573
+ JOIN people ON people.id = search_tree.parent_id
3574
+ WHERE NOT people.id = ANY(path)
3575
+ )
3576
+ SELECT id FROM search_tree ORDER BY path DESC
3577
+ ))
3578
+  (0.2ms) ROLLBACK
3579
+  (0.1ms) BEGIN
3580
+ --------------------------------
3581
+ PersonTest: test_dad_descendents
3582
+ --------------------------------
3583
+ Person Load (0.3ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 2]]
3584
+ Person Load (0.3ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 3]]
3585
+ Person Load (0.9ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3586
+ SELECT id, ARRAY[id]
3587
+ FROM people
3588
+ WHERE id = 2
3589
+ UNION ALL
3590
+ SELECT people.id, path || people.id
3591
+ FROM search_tree
3592
+ JOIN people ON people.parent_id = search_tree.id
3593
+ WHERE NOT people.id = ANY(path)
3594
+ )
3595
+ SELECT id FROM search_tree ORDER BY path
3596
+ ))
3597
+ Person Load (0.6ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3598
+ SELECT id, ARRAY[id]
3599
+ FROM people
3600
+ WHERE id = 2
3601
+ UNION ALL
3602
+ SELECT people.id, path || people.id
3603
+ FROM search_tree
3604
+ JOIN people ON people.parent_id = search_tree.id
3605
+ WHERE NOT people.id = ANY(path)
3606
+ )
3607
+ SELECT id FROM search_tree ORDER BY path
3608
+ ))
3609
+  (0.7ms) SELECT COUNT(*) FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3610
+ SELECT id, ARRAY[id]
3611
+ FROM people
3612
+ WHERE id = 2
3613
+ UNION ALL
3614
+ SELECT people.id, path || people.id
3615
+ FROM search_tree
3616
+ JOIN people ON people.parent_id = search_tree.id
3617
+ WHERE NOT people.id = ANY(path)
3618
+ )
3619
+ SELECT id FROM search_tree ORDER BY path
3620
+ ))
3621
+ Person Load (0.7ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3622
+ SELECT id, ARRAY[id]
3623
+ FROM people
3624
+ WHERE id = 2
3625
+ UNION ALL
3626
+ SELECT people.id, path || people.id
3627
+ FROM search_tree
3628
+ JOIN people ON people.parent_id = search_tree.id
3629
+ WHERE NOT people.id = ANY(path)
3630
+ )
3631
+ SELECT id FROM search_tree ORDER BY path
3632
+ ))
3633
+ Person Load (0.7ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3634
+ SELECT id, ARRAY[id]
3635
+ FROM people
3636
+ WHERE id = 2
3637
+ UNION ALL
3638
+ SELECT people.id, path || people.id
3639
+ FROM search_tree
3640
+ JOIN people ON people.parent_id = search_tree.id
3641
+ WHERE NOT people.id = ANY(path)
3642
+ )
3643
+ SELECT id FROM search_tree ORDER BY path
3644
+ ))
3645
+ Person Load (0.9ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3646
+ SELECT id, ARRAY[id]
3647
+ FROM people
3648
+ WHERE id = 2
3649
+ UNION ALL
3650
+ SELECT people.id, path || people.id
3651
+ FROM search_tree
3652
+ JOIN people ON people.parent_id = search_tree.id
3653
+ WHERE NOT people.id = ANY(path)
3654
+ )
3655
+ SELECT id FROM search_tree ORDER BY path
3656
+ ))
3657
+  (0.1ms) ROLLBACK
3658
+  (0.1ms) BEGIN
3659
+ ----------------------------------
3660
+ PersonTest: test_grandad_ancestors
3661
+ ----------------------------------
3662
+ Person Load (0.4ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 1]]
3663
+ Person Load (1.0ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, parent_id, path) AS (
3664
+ SELECT id, parent_id, ARRAY[id]
3665
+ FROM people
3666
+ WHERE id = 1
3667
+ UNION ALL
3668
+ SELECT people.id, people.parent_id, path || people.id
3669
+ FROM search_tree
3670
+ JOIN people ON people.id = search_tree.parent_id
3671
+ WHERE NOT people.id = ANY(path)
3672
+ )
3673
+ SELECT id FROM search_tree ORDER BY path DESC
3674
+ ))
3675
+  (0.2ms) ROLLBACK
3676
+  (0.1ms) BEGIN
3677
+ ---------------------------------------
3678
+ PersonTest: test_person_fixtures_loaded
3679
+ ---------------------------------------
3680
+ Person Load (0.5ms) SELECT "people".* FROM "people" ORDER BY "people"."id" ASC LIMIT 1
3681
+  (0.1ms) ROLLBACK
3682
+  (0.1ms) BEGIN
3683
+ ---------------------------------------------
3684
+ PersonTest: test_respond_to_all_magic_methods
3685
+ ---------------------------------------------
3686
+ Person Load (0.3ms) SELECT "people".* FROM "people" ORDER BY "people"."id" ASC LIMIT 1
3687
+  (0.1ms) ROLLBACK
3688
+  (0.1ms) BEGIN
3689
+ ----------------------------------------
3690
+ PersonTest: test_responds_to_all_methods
3691
+ ----------------------------------------
3692
+ Person Load (0.2ms) SELECT "people".* FROM "people" ORDER BY "people"."id" ASC LIMIT 1
3693
+  (0.1ms) ROLLBACK
3694
+  (0.1ms) BEGIN
3695
+ --------------------------------
3696
+ PersonTest: test_son_descendents
3697
+ --------------------------------
3698
+ Person Load (0.2ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT 1 [["id", 3]]
3699
+ Person Load (0.6ms) SELECT "people".* FROM "people" WHERE (people.id IN ( WITH RECURSIVE search_tree(id, path) AS (
3700
+ SELECT id, ARRAY[id]
3701
+ FROM people
3702
+ WHERE id = 3
3703
+ UNION ALL
3704
+ SELECT people.id, path || people.id
3705
+ FROM search_tree
3706
+ JOIN people ON people.parent_id = search_tree.id
3707
+ WHERE NOT people.id = ANY(path)
3708
+ )
3709
+ SELECT id FROM search_tree ORDER BY path
3710
+ ))
3711
+  (0.1ms) ROLLBACK
3712
+  (0.1ms) BEGIN
3713
+ ---------------------------------
3714
+ PersonTest: test_tree_roots_scope
3715
+ ---------------------------------
3716
+  (0.4ms) SELECT COUNT(*) FROM "people" WHERE "people"."parent_id" IS NULL
3717
+  (0.1ms) ROLLBACK
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dyson Simmons
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -52,8 +52,8 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Include PostgresTree::ActiveRecordConcern in your models along with a
56
- parent_id field and get access to ancestors and descendents in one query.
55
+ description: Access to Rails 4 ActiveRecord models ancestors and descendents in one
56
+ query.
57
57
  email:
58
58
  - dysonsimmons@gmail.com
59
59
  executables: []
@@ -134,7 +134,7 @@ rubyforge_project:
134
134
  rubygems_version: 2.2.2
135
135
  signing_key:
136
136
  specification_version: 4
137
- summary: ActiveRecord tree structures using PostgreSQL
137
+ summary: Rails 4 ActiveRecord tree structures using PostgreSQL
138
138
  test_files:
139
139
  - test/integration/navigation_test.rb
140
140
  - test/test_helper.rb