Hello, when i create a record, User.create(:login=>''john'', :password => ''password''), active record behaviour is to include every of my fields in the SQL query : INSERT INTO users ("login", "password", "another_column", "yet_another_column") VALUES(''john'', ''password'', NULL, NULL) But i want active record to just include filfulled fields in the query: INSERT INTO users ("login", "password") VALUES(''john'', ''password'') how can i change it? --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is there any reason you want to do this? This is ActiveRecord''s default behaviour and changing it would be a pain. On Jan 9, 2008 11:13 AM, Jean-Sébastien <jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > when i create a record, User.create(:login=>''john'', :password => > ''password''), active record behaviour is to include every of my fields > in the SQL query : > INSERT INTO users ("login", "password", "another_column", > "yet_another_column") VALUES(''john'', ''password'', NULL, NULL) > > But i want active record to just include filfulled fields in the > query: > INSERT INTO users ("login", "password") VALUES(''john'', ''password'') > > how can i change it? > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yes my database has some triggers: some fields are "NOT NULL" but triggers put the good values inside. On Jan 9, 1:45 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there any reason you want to do this? This is ActiveRecord''s default > behaviour and changing it would be a pain. > > On Jan 9, 2008 11:13 AM, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello, > > when i create a record, User.create(:login=>''john'', :password => > > ''password''), active record behaviour is to include every of my fields > > in the SQL query : > > INSERT INTO users ("login", "password", "another_column", > > "yet_another_column") VALUES(''john'', ''password'', NULL, NULL) > > > But i want active record to just include filfulled fields in the > > query: > > INSERT INTO users ("login", "password") VALUES(''john'', ''password'') > > > how can i change it? > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You could move the triggers into the model, depending on what they do. On Jan 9, 2008 11:21 AM, Jean-Sébastien <jeansebastien.ney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > yes my database has some triggers: some fields are "NOT NULL" but > triggers put the good values inside. > > > On Jan 9, 1:45 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Is there any reason you want to do this? This is ActiveRecord''s default > > behaviour and changing it would be a pain. > > > > On Jan 9, 2008 11:13 AM, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > > > Hello, > > > when i create a record, User.create(:login=>''john'', :password => > > > ''password''), active record behaviour is to include every of my fields > > > in the SQL query : > > > INSERT INTO users ("login", "password", "another_column", > > > "yet_another_column") VALUES(''john'', ''password'', NULL, NULL) > > > > > But i want active record to just include filfulled fields in the > > > query: > > > INSERT INTO users ("login", "password") VALUES(''john'', ''password'') > > > > > how can i change it? > > > > -- > > Ryan Bigghttp://www.frozenplague.net > > Feel free to add me to MSN and/or GTalk as this email. > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
no i can''t: this database is not only acceed my rails processes, we have some java tasks too. I think the better way is to modify our triggers. On Jan 9, 1:53 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You could move the triggers into the model, depending on what they do. > > On Jan 9, 2008 11:21 AM, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > yes my database has some triggers: some fields are "NOT NULL" but > > triggers put the good values inside. > > > On Jan 9, 1:45 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Is there any reason you want to do this? This is ActiveRecord''s default > > > behaviour and changing it would be a pain. > > > > On Jan 9, 2008 11:13 AM, Jean-Sébastien <jeansebastien....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > > Hello, > > > > when i create a record, User.create(:login=>''john'', :password => > > > > ''password''), active record behaviour is to include every of my fields > > > > in the SQL query : > > > > INSERT INTO users ("login", "password", "another_column", > > > > "yet_another_column") VALUES(''john'', ''password'', NULL, NULL) > > > > > But i want active record to just include filfulled fields in the > > > > query: > > > > INSERT INTO users ("login", "password") VALUES(''john'', ''password'') > > > > > how can i change it? > > > > -- > > > Ryan Bigghttp://www.frozenplague.net > > > Feel free to add me to MSN and/or GTalk as this email. > > -- > Ryan Bigghttp://www.frozenplague.net > Feel free to add me to MSN and/or GTalk as this email.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jean-sébastien Jney wrote:> no i can''t: this database is not only acceed my rails processes, we > have some java tasks too. > I think the better way is to modify our triggers.You could try adding this to your user model, ignore_column "another_column" ignore_column "yet_another_column" after extending ActiveRecord::Base with class ActiveRecord::Base def self.ignore_column(column_name) case column_name when String, Symbol self.columns_hash.delete(column_name.to_s) self.columns.delete_if {|c| c.name == column_name.to_s} when Regexp self.columns_hash.delete_if { |k,v| column_name.match(k)} self.columns.delete_if { |c| column_name.match(c.name)} end end end Or do you need to read these columns as well? Stephan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yes i need to read them :(. I already use same kind of hack on other fields. On Jan 9, 2:04 am, Stephan Wehner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Jean-sébastien Jney wrote: > > no i can''t: this database is not only acceed my rails processes, we > > have some java tasks too. > > I think the better way is to modify our triggers. > > You could try adding this to your user model, > > ignore_column "another_column" > ignore_column "yet_another_column" > > after extending ActiveRecord::Base with > > class ActiveRecord::Base > def self.ignore_column(column_name) > case column_name > when String, Symbol > self.columns_hash.delete(column_name.to_s) > self.columns.delete_if {|c| c.name == column_name.to_s} > when Regexp > self.columns_hash.delete_if { |k,v| column_name.match(k)} > self.columns.delete_if { |c| column_name.match(c.name)} > end > end > end > > Or do you need to read these columns as well? > > Stephan > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jean-sébastien Jney wrote:> yes i need to read them :(. I already use same kind of hack on other > fields. > > On Jan 9, 2:04 am, Stephan Wehner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>In that case you can extend the User model with a UserWrite model, which has those columns hidden. The UserWrite model is only used by the controller for updates/inserts. Stephan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok, i''ll try your solution, thanks everyone for so quick answers On 9 jan, 03:54, Stephan Wehner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Jean-sébastien Jney wrote: > > yes i need to read them :(. I already use same kind of hack on other > > fields. > > > On Jan 9, 2:04 am, Stephan Wehner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > In that case you can extend the User model with a UserWrite model, which > has those columns hidden. The UserWrite model is only used by the > controller for updates/inserts. > > Stephan > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---