chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

Searching for Project by name broken #107

Open roboyak opened 9 years ago

roboyak commented 9 years ago

Nice work, fantastic gem for the ruby community, I came across this issue while using gem version 0.9.18:

Searching for Project by name broken using the finders:

broken

SugarCRM::Project.find_by_name("Netflix")

SugarCRM logs are showing a pluralized table name when it shouldn't be:

AND jt2.deleted=0 where (projects.name = 'Netflix') AND project.deleted=0: MySQL error 1054: Unknown column 'projects.name' in 'where clause'

Looks like it should be where (project.name = 'Netflix') the singular version.

work around

This alternative method does work however when searching for projects by name:

SugarCRM.connection.get_entry_list( "Project", "project.name = 'Netflix'" )

chicks commented 9 years ago

Ooof, thanks. Not sure if I'll ever fix this one but good to know!

roboyak commented 9 years ago

If you can point me at the section of code where you think it might be I'll create a pull request for you.

chicks commented 9 years ago

So I haven't dug into this, but here's my best guess: We use the Sugar metadata to build dynamic finder methods (look here: https://github.com/chicks/sugarcrm/blob/master/lib/sugarcrm/finders/finder_methods.rb#L161). In 99% of the cases, the table name matches the module name, except this case. You will need to update this line: https://github.com/chicks/sugarcrm/blob/master/lib/sugarcrm/finders/finder_methods.rb#L100 to reference the table name, instead of the module name.

Please run the unit tests before submitting!

Hope that helps!

Cheers,

-Charles

roboyak commented 9 years ago

no problem. thank for the pointers.