sugarcrm 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -76,6 +76,13 @@ e.g. SugarCRM::Contacts.find_by_title("VP of Sales") will work, but SugarCRM::Co
76
76
 
77
77
  # Use the HTTP Connection and SugarCRM API to load the Admin user
78
78
  SugarCRM.connection.get_entry("Users", 1)
79
+
80
+ # Retrieve the first 10 Accounts with a zip code between 10000 and 10500
81
+ SugarCRM::Account.all({
82
+ :conditions => { :billing_address_postalcode => ["> '10000'", "<= '10500'" ] },
83
+ :limit => '10',
84
+ :order_by => 'billing_address_postalcode'
85
+ })
79
86
 
80
87
  # Retrieve all Accounts by user name (direct API method)
81
88
  SugarCRM.connection.get_entry_list(
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.8.2
@@ -54,9 +54,9 @@ module SugarCRM; module AttributeMethods
54
54
  case attr_type_for(attribute)
55
55
  when "bool"
56
56
  case @attributes[attribute]
57
- when TrueClass:
57
+ when TrueClass
58
58
  next
59
- when FalseClass:
59
+ when FalseClass
60
60
  next
61
61
  else
62
62
  @errors.add "#{attribute} must be true or false"
data/lib/sugarcrm/base.rb CHANGED
@@ -129,8 +129,23 @@ module SugarCRM; class Base
129
129
  # If we dont have conditions, just return an empty query
130
130
  return "" unless options[:conditions]
131
131
  conditions = []
132
- options[:conditions].each_pair do |column, value|
133
- conditions << "#{self._module.table_name}.#{column} = \'#{value}\'"
132
+ options[:conditions].each_pair do |column, v|
133
+ v = [] << v unless v.class == Array
134
+
135
+ v.each{|value|
136
+ # parse operator in cases where (e.g.) :attribute => '>= some_value', fallback to '=' operator as default
137
+ operator = value.to_s[/^([<>=]*)(.*)$/,1]
138
+ operator = '=' if operator.nil? || operator.strip == ''
139
+
140
+ value = $2 # strip the operator from value passed to query
141
+ value = value.strip[/'?([^']*)'?/,1]
142
+ unless column =~ /_c$/ # attribute name ending with _c implies a custom attribute
143
+ condition_attribute = "#{self._module.table_name}.#{column}"
144
+ else
145
+ condition_attribute = column # if setting a condition on a customer attribute, don't add model table name (or query breaks)
146
+ end
147
+ conditions << "#{condition_attribute} #{operator} \'#{value}\'"
148
+ }
134
149
  end
135
150
  conditions.join(" AND ")
136
151
  end
@@ -270,7 +285,7 @@ module SugarCRM; class Base
270
285
  end
271
286
 
272
287
  VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset,
273
- :order, :select, :readonly, :group, :having, :from, :lock ]
288
+ :order_by, :select, :readonly, :group, :having, :from, :lock ]
274
289
 
275
290
  def validate_find_options(options) #:nodoc:
276
291
  options.assert_valid_keys(VALID_FIND_OPTIONS)
@@ -74,6 +74,16 @@ class TestSugarCRM < Test::Unit::TestCase
74
74
  #SugarCRM.connection.debug = false
75
75
  end
76
76
 
77
+ should "support searching based on conditions" do
78
+ accounts = SugarCRM::Account.all({
79
+ :conditions => { :billing_address_postalcode => ["> '70000'", "< '72000'" ] },
80
+ :limit => '10',
81
+ :order_by => 'billing_address_postalcode'
82
+ })
83
+ assert_instance_of Array, accounts
84
+ assert_instance_of SugarCRM::Account, accounts.first
85
+ end
86
+
77
87
  should "return an an instance of itself when sent #find(id)" do
78
88
  assert_instance_of SugarCRM::User, SugarCRM::User.find(1)
79
89
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcrm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 59
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 1
10
- version: 0.8.1
9
+ - 2
10
+ version: 0.8.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Carl Hicks
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-08 00:00:00 -08:00
18
+ date: 2010-12-14 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency