sugarcrm 0.9.3 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -115,6 +115,11 @@ Instead of SugarCRM.connection.get_entry("Users", "1") you could use SugarCRM::U
115
115
  :conditions => { :billing_address_postalcode => "<> NULL" }
116
116
  })
117
117
 
118
+ # Retrieve all Accounts with 'Fund' in their name
119
+ SugarCRM::Account.all({
120
+ :conditions => { :name => "LIKE '%Fund%'" } # note that SQL operators must be uppercase
121
+ })
122
+
118
123
  # Look up the fields for a given module
119
124
  SugarCRM::Module.find("Accounts").fields
120
125
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.3
1
+ 0.9.4
@@ -17,6 +17,29 @@ module SugarCRM; module AttributeMethods
17
17
  end
18
18
  table_name
19
19
  end
20
+ # Takes a condition like: [:zip, ["> 75000", "< 80000"]]
21
+ # and flattens it to: ["accounts.zip > 75000", "accounts.zip < 80000"]
22
+ def flatten_conditions_for(condition)
23
+ conditions = []
24
+ attribute, attribute_conditions = condition
25
+ # Make sure we wrap the attribute condition in an array for EZ handling...
26
+ Array.wrap(attribute_conditions).each do |attribute_condition|
27
+ # parse operator in cases where:
28
+ # :attribute => '>= some_value',
29
+ # :attribute => "LIKE '%value%'",
30
+ # fallback to '=' operator as default]
31
+ operator = attribute_condition.to_s[/^([!<>=]*(LIKE|IS|NOT|\s)*)(.*)$/,1].strip!
32
+ # Default to = if we can't resolve the condition.
33
+ operator ||= '='
34
+ # Extract value from query
35
+ value = $3
36
+ # TODO: Write a test for sending invalid attribute names.
37
+ # strip single quotes
38
+ value = value.strip[/'?([^']*)'?/,1]
39
+ conditions << "#{table_name_for(attribute)}.#{attribute} #{operator} \'#{value}\'"
40
+ end
41
+ conditions
42
+ end
20
43
  end
21
44
 
22
45
  # Determines if attributes or associations have been changed
data/lib/sugarcrm/base.rb CHANGED
@@ -152,23 +152,14 @@ module SugarCRM; class Base
152
152
  query = query_from_options(options)
153
153
  SugarCRM.connection.get_entry_list(self._module.name, query, options)
154
154
  end
155
-
155
+
156
156
  def query_from_options(options)
157
157
  # If we dont have conditions, just return an empty query
158
158
  return "" unless options[:conditions]
159
159
  conditions = []
160
- options[:conditions].each_pair do |column, v|
161
- v = [] << v unless v.class == Array
162
-
163
- v.each{|value|
164
- # parse operator in cases where (e.g.) :attribute => '>= some_value', fallback to '=' operator as default
165
- operator = value.to_s[/^([<>=]*)(.*)$/,1]
166
- operator = '=' if operator.nil? || operator.strip == ''
167
-
168
- value = $2 # strip the operator from value passed to query
169
- value = value.strip[/'?([^']*)'?/,1]
170
- conditions << "#{table_name_for(column)}.#{column} #{operator} \'#{value}\'"
171
- }
160
+ options[:conditions].each do |condition|
161
+ # Merge the result into the conditions array
162
+ conditions |= flatten_conditions_for(condition)
172
163
  end
173
164
  conditions.join(" AND ")
174
165
  end
@@ -15,7 +15,17 @@ module SugarCRM
15
15
  @name = name
16
16
  @klass = name.classify
17
17
  @table_name = name.tableize
18
- @custom_table_name = @table_name + "_cstm"
18
+
19
+ # set table name for custom attibutes
20
+ # custom attributes are contained in a table named after the module, with a '_cstm' suffix
21
+ # the module's table name must be tableized for the modules that ship with SugarCRM
22
+ # for custom modules (created in the Studio), table name don't need to be tableized: the name passed to the constructor is already tableized
23
+ unless name.downcase == name # this module is a custom module (custom module names are all lower_case, whereas SugarCRM modules are CamelCase
24
+ @custom_table_name = @table_name + "_cstm"
25
+ else
26
+ @custom_table_name = name + "_cstm"
27
+ end
28
+
19
29
  @fields = {}
20
30
  @link_fields = {}
21
31
  @fields_registered = false
@@ -97,6 +97,14 @@ class TestSugarCRM < Test::Unit::TestCase
97
97
  assert_instance_of SugarCRM::Account, accounts.first
98
98
  end
99
99
 
100
+ should "support searching based on SQL operators" do
101
+ accounts = SugarCRM::Account.all({
102
+ :conditions => { :name => "LIKE '%Inc%'" }
103
+ })
104
+ assert accounts
105
+ assert_instance_of SugarCRM::Account, accounts.first
106
+ end
107
+
100
108
  should "return an an instance of itself when sent #find(id)" do
101
109
  assert_instance_of SugarCRM::User, SugarCRM::User.find(1)
102
110
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 3
9
- version: 0.9.3
8
+ - 4
9
+ version: 0.9.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Carl Hicks
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-05 00:00:00 -08:00
17
+ date: 2011-01-07 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -193,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
193
  requirements:
194
194
  - - ">="
195
195
  - !ruby/object:Gem::Version
196
- hash: -1102479478873110582
196
+ hash: -2099227492656529688
197
197
  segments:
198
198
  - 0
199
199
  version: "0"