Bergrebell / CyberCoach

1 stars 1 forks source link

clean integration of rails query methods in Facade::BaseFacade #53

Closed lexruee closed 9 years ago

lexruee commented 9 years ago

I'm thinking of removing the class methods find_by and where in Facade::BaseFacade.

The reason is that Facade::BaseFacade can never mimic the rails fluent query api.

# rails way, fluent query api
User.limit(10).where(location: 'Bern').where("age < ? ", 40 )

Currently the Facade cannot wrap such complex calls.

My solution to this problem: inversion of control using a block

Facade::User.query do
    User.limit(10).where(location: 'Bern').where("age < ? ", 40 )
end

This simplifies everyhting and we have less code in the Facade. Big advantage: you can use all rails query methods inside the query block. For me it seems to be a simple and proper solution.

lexruee commented 9 years ago

Commit c5c88e7af943749c93feee87a0b6dc1a63704286 closes this issue. The methods find_by and where are not removed, but should be refactored in the future using:

Facade::User.query do
   User.all # just an example
end

# or

Facade::SportSession.query do
     SportSession.all # just an example
end