bowtie 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
data/bowtie.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{bowtie}
3
- s.version = "0.4.4"
3
+ s.version = "0.4.5"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Tomás Pollak"]
@@ -57,6 +57,18 @@ module Bowtie
57
57
  assoc.class == DataMapper::Associations::OneToOne::Relationship
58
58
  end
59
59
 
60
+ # i have to say this: datamapper sucks. when calling record.association.count
61
+ # it actually fetches all the records, builds an array and then calls count on
62
+ # that array.
63
+ def self.get_count(record, association)
64
+ association_key = "#{record.class.name.downcase}_#{record.class.primary_key}"
65
+ begin
66
+ repository.adapter.select("select count(*) from #{association} where #{association_key} = ?", record.primary_key)
67
+ rescue DataObjects::SQLError => e # probably has_many :through => association
68
+ ''
69
+ end
70
+ end
71
+
60
72
  module Helpers
61
73
 
62
74
  def total_entries(resources)
@@ -48,6 +48,10 @@ module Bowtie
48
48
  assoc.class == MongoMapper::Plugins::Associations::OneAssociation
49
49
  end
50
50
 
51
+ def self.get_count(record, association)
52
+ record.send(association).count
53
+ end
54
+
51
55
  module Helpers
52
56
 
53
57
  def total_entries(resources)
@@ -79,7 +79,7 @@ module Bowtie
79
79
  if Bowtie.has_one_association?(assoc) || Bowtie.belongs_to_association?(assoc)
80
80
  html += (r.send(rel_name).nil? ? 'nil' : "View #{rel_name.to_s}")
81
81
  else
82
- html += r.send(rel_name).count.to_s
82
+ html += Bowtie.get_count(r, rel_name).to_s
83
83
  end
84
84
  html += "</a></td>"
85
85
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bowtie
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
- prerelease: false
4
+ hash: 5
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 4
10
- version: 0.4.4
9
+ - 5
10
+ version: 0.4.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Tom\xC3\xA1s Pollak"
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  requirements: []
107
107
 
108
108
  rubyforge_project: bowtie
109
- rubygems_version: 1.3.7
109
+ rubygems_version: 1.5.2
110
110
  signing_key:
111
111
  specification_version: 3
112
112
  summary: Bowtie Admin Scaffold