views:

31

answers:

3

I am a Rails newbie and would really appreciate if someone converted these SQLs to complete modules for rails. I know its a lot to ask but I can't just use find_by_sql for all of them. Or can I?

These are the SQLs (they run on MS-SQL):

SELECT STANJA_NA_DAN_POSTAVKA.STA_ID, STP_DATE, STP_TIME, STA_OPIS, STA_SIFRA, STA_POND FROM STANJA_NA_DAN_POSTAVKA INNER JOIN STANJA_NA_DAN ON(STANJA_NA_DAN.STA_ID=STANJA_NA_DAN_POSTAVKA.STA_ID) WHERE ((OSE_ID=10)AND (STANJA_NA_DAN_POSTAVKA.STP_DATE>={d '2010-03-30'}) AND (STANJA_NA_DAN_POSTAVKA.STP_DATE<={d '2010-03-30'}))

SELECT ZIGI_OBDELANI.OSE_ID,
ZIGI_OBDELANI.DOG_ID AS DOG_ID,
ZIGI_OBDELANI.ZIO_DATUM AS DATUM,
ZIGI_PRICETEK.ZIG_TIME_D AS ZIG_PRICETEK,
ZIGI_KONEC.ZIG_TIME_D AS ZIG_KONEC
FROM (ZIGI_OBDELANI INNER JOIN ZIGI ZIGI_PRICETEK ON ZIGI_OBDELANI.ZIG_ID_PRICETEK = ZIGI_PRICETEK.ZIG_ID )
INNER JOIN ZIGI ZIGI_KONEC ON ZIGI_OBDELANI.ZIG_ID_KONEC = ZIGI_KONEC.ZIG_ID
WHERE (ZIGI_OBDELANI.OSE_ID = 10) AND (ZIGI_OBDELANI.ZIO_DATUM >= {d '2010-03-30'}) AND (ZIGI_OBDELANI.ZIO_DATUM <= {d '2010-03-30'}) AND (ZIGI_PRICETEK.ZIG_VELJAVEN <> 0) AND (ZIGI_KONEC.ZIG_VELJAVEN <> 0)
ORDER BY ZIGI_OBDELANI.OSE_ID, ZIGI_PRICETEK.ZIG_TIME ASC

These SQLs are daily working hours and I got them as is. Also I got Database with it which (as you can see from the SQL-s) is not in Rails conventions. As a P.S.:

  1. Things like STP_DATE>={d'2010-03-30'}) are of course dates (in Slovenian date notation) and will be replaced with a variable (date), so that the user could choose date from and date to.

  2. All of this data will be shown in the same page in the table,so maybe all in one module? Or many?; if this helps, maybe.

So can someone help me? Its for my work and its my 1st project and I am a Rails newbie and the bosses are getting inpatient(they are getting quite loud actually)

Thank you very very much!

So again I would really apreciate if someone could do a relevant model part for at least one of the complicated SQLs. I will read all the data in one controller and in one action. All will be done in one run.

A: 

create views for these sqls in the database and a model for each view.

Can't because peaces like {d '2010-03-30'}) are included by application. These SQLs are just examples for one particular case. In reality dates and user id's (for example OSE_ID=10) are inputted by user
Hoornet
A: 

This is not really the place to ask people to "Do my work for me" there are other sites like rent-a-coder where you can do that.

This is a place to ask for help however and I can give you some pointers.

The first thing you should do is start to work out what your models are. You could try auto-generating your models using Dr Nics magic models though I expect that the fact that the database does not follow ActiveRecord conventions may be a problem for you.

I have had some success in the past with legacy databases by renaming the tables and columns to Rails conventions and providing a view that reflects the current naming convention for the existing legacy applications to use. If you were able to do that then your life would be easier as you could then use generators like Magic Models or Ryan Bates nifty scaffold to provide you a basic structure to then start working on.

Hope this helps and good luck with your project.

Steve Weet
This is why I said its difficult. I don't need the work done for me. I need an example of at least one of the complicated SQLs I wrote up converted so that I can model the rest on it. All the other text I wrote in was as a help so that people would know what's it about. Also I did took a look at 'Dr Nics magic models' previously I wrote this but don't believe it helps in this case.Also I have a basic structure but its all done with SQLs not at all in Rails style. Its done as I would do it in c++ Application. All manually.
Hoornet
+1  A: 

Actually the Rails way to handle this, is to create models for each table, and create the relations inside the model.

Since it is a legacy-model you will have to do the following

class Stanja < ActiveRecord::Base
  set_table_name 'STANJA_NA_DAN'
  set_primary_key 'your-primary-key'
end

class Postavka < ActiveRecord::Base
  set_table_name 'STANJA_NA_DAN_POSTAVKA'
  set_primary_key 'STA_ID'
  has_many :stanjas, :foreign_key => 'sta_id', :primary_key => 'sta_id'
end  

something like that. Without knowing your model and what the hell your table-names mean :) But i hope it gets you started.

Success!!

nathanvda