[Rails] Re: SQL queries in Rails

2008-11-06 Thread Gabriel Laskar
On Thu, Nov 6, 2008 at 4:47 PM, Phillip Koebbe <[EMAIL PROTECTED]> wrote: > The Neurochild wrote: >> So I put both methods on one files and load them in the environment? >> That's it. > > Right. Here's the skinny on how I do it: > > I have a file > > {RAILS_ROOT}/lib/pg_ext.rb > > that contains th

[Rails] Re: SQL queries in Rails

2008-11-06 Thread Phillip Koebbe
The Neurochild wrote: > On Nov 7, 9:06 am, Phillip Koebbe <[EMAIL PROTECTED]> > wrote: >> You don't need a class since you're just building a sql statement. You >> need to deal with tables and columns, not classes. Look back at how I >> defined foreign_key and delete_foreign_key. delete_foreign_ke

[Rails] Re: SQL queries in Rails

2008-11-06 Thread The Neurochild
On Nov 7, 9:06 am, Phillip Koebbe <[EMAIL PROTECTED]> wrote: > You don't need a class since you're just building a sql statement. You > need to deal with tables and columns, not classes. Look back at how I > defined foreign_key and delete_foreign_key. delete_foreign_key assumes a > naming conven

[Rails] Re: SQL queries in Rails

2008-11-06 Thread Phillip Koebbe
The Neurochild wrote: >> delete_foreign_key :orders, :customer_id > > I'm not sure, but I think there's something missing: the class name. > Or isn't that necessary here? If yes, can we put a name to it or what > kind of class is it? > You don't need a class since you're just building a sql sta

[Rails] Re: SQL queries in Rails

2008-11-06 Thread The Neurochild
On Nov 5, 9:39 am, Phillip Koebbe <[EMAIL PROTECTED]> wrote: > The syntax that I use for PostgreSQL is this: > > def foreign_key(foreign_table, foreign_column, primary_table, > primary_column = :id) > execute " > alter table #{foreign_table.to_s} > add constraint fk_#{foreign_table.to_

[Rails] Re: SQL queries in Rails

2008-11-05 Thread Phillip Koebbe
The Neurochild wrote: > > Do I have to create the initializers directory? Because Rails didn't > created it. > Initializers come with Rails 2.x (not sure if which point release, maybe the first one). You'll have to use the environment.rb method in 1.2.x. > I tested the config for PostgreSQL a

[Rails] Re: SQL queries in Rails

2008-11-05 Thread Phillip Koebbe
Gabriel Laskar wrote: > In order to have this with initializers, it is more simple, > you just drop the file in the config/initializers/ directory, and it > will be required by default > at boot of the rails application. > > The initializers have been realized in order to avoid all the stuff in >

[Rails] Re: SQL queries in Rails

2008-11-05 Thread The Neurochild
On Nov 5, 3:57 pm, "Gabriel Laskar" <[EMAIL PROTECTED]> wrote: > In order to have this with initializers, it is more simple, > you just drop the file in the config/initializers/ directory, and it > will be required by default > at boot of the rails application. > > The initializers have been rea

[Rails] Re: SQL queries in Rails

2008-11-04 Thread Gabriel Laskar
On Tue, Nov 4, 2008 at 9:22 PM, Phillip Koebbe <[EMAIL PROTECTED]> wrote: > There is also a way to do something like this with initializers, but I > haven't yet taken the time to research it. > In order to have this with initializers, it is more simple, you just drop the file in the config/initial

[Rails] Re: SQL queries in Rails

2008-11-04 Thread The Neurochild
Thanks, man! I'm going to try it right now And I'll post the results later. Greetings! The Neurochild --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to

[Rails] Re: SQL queries in Rails

2008-11-04 Thread Phillip Koebbe
The Neurochild wrote: > Whoa! Awesome! I would like to apply that and the foreign key thing, > but is there a folder where I can save and call my file? Where do you > place it in your case? > Different people have different ways of organizing things like this. I put stuff like this in files in

[Rails] Re: SQL queries in Rails

2008-11-04 Thread The Neurochild
On Nov 5, 2:40 pm, Phillip Koebbe <[EMAIL PROTECTED]> wrote: > Each database adapter has the ability to define the database types Rails > uses when building DDL. The method used is native_database_types, which > is, in the case of PostgreSQL, found in the PostgreSQL class of the > ConnectionAdap

[Rails] Re: SQL queries in Rails

2008-11-04 Thread Phillip Koebbe
The Neurochild wrote: > On Nov 5, 2:07 pm, Phillip Koebbe <[EMAIL PROTECTED]> > wrote: >> if you want to use a char instead of a character varying, you can >> override native_database_types to include a :char definition. > > Really? How do I override it? I'm interested. Sorry if I have many > tri

[Rails] Re: SQL queries in Rails

2008-11-04 Thread The Neurochild
On Nov 5, 2:07 pm, Phillip Koebbe <[EMAIL PROTECTED]> wrote: > if you want to use a char instead of a character varying, you can > override native_database_types to include a :char definition. Really? How do I override it? I'm interested. Sorry if I have many trivial questions, but I'm really n

[Rails] Re: SQL queries in Rails

2008-11-04 Thread Phillip Koebbe
The Neurochild wrote: > But what about the datatypes of SQL? First, I have some columns with a > char datatype and I want them that way. Secondly, I saw, when I define > a :string column with a :default value, that value doesn't appear > reflected in the database. > > In the last catch, what coul

[Rails] Re: SQL queries in Rails

2008-11-04 Thread The Neurochild
But what about the datatypes of SQL? First, I have some columns with a char datatype and I want them that way. Secondly, I saw, when I define a :string column with a :default value, that value doesn't appear reflected in the database. In the last catch, what could be wrong? I'm using Rails 1.2.6

[Rails] Re: SQL queries in Rails

2008-11-04 Thread Phillip Koebbe
The Neurochild wrote: > Hi... > > I want to know the equivalent instructions to insert, update, search > and delete a registry. I know Rails can do it easily Thanks to > ActiveRecord, but here's the catch: I'm using PostgreSQL. As I'm using > SQL to do the migration (Including the foreign keys),