I may be overlooking something really obvious here but I''m not getting
it. I have a Category model. Categories can have sub categories and
parent categories, but when a category doesn''t have a parent category,
its "parent_categoryid" field is set to null. As far as I know, what I
am doing here has been working in the past because there are many
categories in my categories table with null parent_categoryid fields.
For some reason, when I do:
c = Category.find(12345)
c.save
It returns false when c.parent_categoryid = NULL, and c.errors says
#<ActiveRecord::Errors:0xb708ce08
@errors={"parent_categoryid"=>["is
not a number"]}, ...
In the DB on the exact same record, I can do:
update categories set parent_categoryid = NULL where id = 12345;
And it works just fine. Any ideas why I''m getting this problem? I am
running Rails v1.2.6, PostgreSQL 8.2.4, and Ruby 1.8.6. The relevant
database constraints are:
Table "public.categories"
Column | Type |
Modifiers
-------------------+---------
+--------------------------------------------------------------------------
id | integer | not null default
nextval(''categories_id_seq''::regclass)
parent_categoryid | integer |
...
Indexes:
"categories_parent_categoryid" btree (parent_categoryid)
Foreign-key constraints:
"$1" FOREIGN KEY (parent_categoryid) REFERENCES categories(id) ON
DELETE CASCADE
Thanks for any help you can offer.
Matt
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Naturally, I figure it out 5 minutes after I post the message. Someone slipped a "validates_numericality_of :parent_categoryid" in the Category model without my knowing. On May 19, 4:24 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I may be overlooking something really obvious here but I''m not getting > it. I have a Category model. Categories can have sub categories and > parent categories, but when a category doesn''t have a parent category, > its "parent_categoryid" field is set to null. As far as I know, what I > am doing here has been working in the past because there are many > categories in my categories table with null parent_categoryid fields. > For some reason, when I do: > > c = Category.find(12345) > c.save > > It returns false when c.parent_categoryid = NULL, and c.errors says > #<ActiveRecord::Errors:0xb708ce08 @errors={"parent_categoryid"=>["is > not a number"]}, ... > > In the DB on the exact same record, I can do: > > update categories set parent_categoryid = NULL where id = 12345; > > And it works just fine. Any ideas why I''m getting this problem? I am > running Rails v1.2.6, PostgreSQL 8.2.4, and Ruby 1.8.6. The relevant > database constraints are: > > Table "public.categories" > Column | Type | > Modifiers > -------------------+--------- > +-------------------------------------------------------------------------- > id | integer | not null default > nextval(''categories_id_seq''::regclass) > parent_categoryid | integer | > ... > Indexes: > "categories_parent_categoryid" btree (parent_categoryid) > Foreign-key constraints: > "$1" FOREIGN KEY (parent_categoryid) REFERENCES categories(id) ON > DELETE CASCADE > > Thanks for any help you can offer. > > Matt--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 19 May 2008, at 23:24, Matt White wrote:> > I may be overlooking something really obvious here but I''m not getting > it. I have a Category model. Categories can have sub categories and > parent categories, but when a category doesn''t have a parent category, > its "parent_categoryid" field is set to null. As far as I know, what I > am doing here has been working in the past because there are many > categories in my categories table with null parent_categoryid fields. > For some reason, when I do: > > c = Category.find(12345) > c.save > > It returns false when c.parent_categoryid = NULL, and c.errors says > #<ActiveRecord::Errors:0xb708ce08 @errors={"parent_categoryid"=>["is > not a number"]}, ...Sounds like you''ve got a (ActiveRecord) validation on that column. Fred> > > In the DB on the exact same record, I can do: > > update categories set parent_categoryid = NULL where id = 12345; > > And it works just fine. Any ideas why I''m getting this problem? I am > running Rails v1.2.6, PostgreSQL 8.2.4, and Ruby 1.8.6. The relevant > database constraints are: > > Table "public.categories" > Column | Type | > Modifiers > -------------------+--------- > + > -------------------------------------------------------------------------- > id | integer | not null default > nextval(''categories_id_seq''::regclass) > parent_categoryid | integer | > ... > Indexes: > "categories_parent_categoryid" btree (parent_categoryid) > Foreign-key constraints: > "$1" FOREIGN KEY (parent_categoryid) REFERENCES categories(id) ON > DELETE CASCADE > > > Thanks for any help you can offer. > > Matt > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---