Are you talking about doing Unions in SQL? Or do you have multiple distinct results from different tables that you want to aggregate?
Jorg Lueke wrote:
Are you talking about doing Unions in SQL? Or do you have multiple distinct results from different tables that you want to aggregate?
Jorg
I'm talking about setting up a parts of sql like
var1 = SELECT
jobs.id,
jobs.location,
jobs.title,
jobs.company,
jobs.description,
jobs.url
FROM
jobs
var2 = WHERE
jobs.id > 0
AND jobs.id = jobs_categories.job_id
.................................
var3 = ta na na na GROUP BY categories.id
ORDER BY categories.name ASC
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
and if defined?(some_value) then
query = var1+vart3
else
!defined?(some_value) then
query = var1+vart2+var4
else
!defined?(some_value) then
query = var1+vart3+var4
end
something like that!
Or if u have a bather solution I'm listening!
Thanks!
Oh I see. That's what I do. I actually have a model (not an active record base) that just generates SQL and it does exactly what you have. Input depends on the specific function, the pieces are added with ruby and the final sql in returned. Then I just access the methods from whatever controller needs them. It keeps all the sql generation in one place.
Jorg Lueke wrote:
Oh I see. That's what I do. I actually have a model (not an active record base) that just generates SQL and it does exactly what you have. Input depends on the specific function, the pieces are added with ruby and the final sql in returned. Then I just access the methods from whatever controller needs them. It keeps all the sql generation in one place.
Sounds cool and clean. Can you tell me hay u do it please. thanks!