Given:
class Program < ActiveRecord::Base
has_many :organizations
end
class Organization < ActiveRecord::Base
belongs_to :program
end
Use Case:
1. Create Program through AS called "Program 1" (verify successful)
2. Create Organization through AS called "Org 1", select "Program 1"
in select list and click "Add Existing" (verify Org 1 created
successfully)
3. Create another Organization through AS call "Org 2" selecting the
same Program as Org 1.
What AS does at that point is strange, it first goes and sets "Org 1"s
program to null, and then goes and creates "Org 2" with that program.
It's like AS thinks the relationship is has_one/belongs_to instead of
has_many/belongs_to. It won't allow multiple Org rows attached to the
same Program...which it darn well should.
What am I missing? (something simple I'm sure)
I have tried it with 3.1.10 and it's working. Can you tried updating
active_scaffold? Have you overrided some controller or helper methods, or some
views?
I haven't modified the controllers at all yet, just default
configuration on the AS controllers:
class OrganizationsController < ApplicationController
active_scaffold :organization do |conf|
end
end
class ProgramsController < ApplicationController
active_scaffold :program do |conf|
end
end
On Nov 28, 6:24 am, Sergio Cambra <ser...@entrecables.com> wrote:
> On Sábado, 26 de noviembre de 2011 17:28:00 Kyle escribió:
>
> > Should have mentioned this is using Rails 3.1.1 and active_scaffold
> > 3.1.8
>
> I have tried it with 3.1.10 and it's working. Can you tried updating
> active_scaffold?
Will do.
> Have you overrided some controller or helper methods, or some
> views?
Have not overridden anything, default controllers and helpers. All
I've done is generate scaffolds with the AS generator, fill in the
migrations, migrate, define models as previously shown. That's it.
It's been a couple years since I've used AS, but I would expect this
basic of a use case to still be the same and work with minimal effort.
Yes, it should work, I have fixed the bug in master branch.
Started POST "/organizations" for 127.0.0.1 at 2011-11-29 11:27:23
-0700
Processing by OrganizationsController#create as JS
Parameters: {"utf8"=>"✓", "authenticity_token"=>"f2SgrBTEMh9JupF
+jXiZtrSy77Rf0ifXk+EOM7PmEhk=", "record"=>{"name"=>"Org 3",
"email"=>"kyle....@gmail.com", "address_1"=>"", "address_2"=>"",
"city"=>"", "phone"=>"", "state"=>"", "url"=>"", "zip"=>"",
"program"=>{"name"=>"Demo", "description"=>"Demo program", "id"=>"1"},
"products"=>{"1322591204075"=>{"name"=>"", "description"=>""}}},
"associated_id"=>"1", "commit"=>"Create"}
Program Load (0.1ms) SELECT "programs".* FROM "programs" WHERE
"programs"."id" = ? LIMIT 1 [["id", "1"]]
Organization Load (0.2ms) SELECT "organizations".* FROM
"organizations" WHERE "organizations"."program_id" = 1
Here's where it sets all existing organization.program_id values to
NULL ...WHY??
SQL (0.5ms) UPDATE "organizations" SET "program_id" = NULL WHERE
"organizations"."program_id" = 1 AND "organizations"."id" IN (1)
After that now it creates the new org...
SQL (45.0ms) INSERT INTO "organizations" ("address_1", "address_2",
"city", "created_at", "email", "name", "phone", "program_id", "state",
"updated_at", "url", "zip") VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["address_1", nil],
["address_2", nil], ["city", nil], ["created_at", Tue, 29 Nov 2011
18:27:23 UTC +00:00], ["email", "kyle....@gmail.com"], ["name",
"Org 3"], ["phone", nil], ["program_id", 1], ["state", nil],
["updated_at", Tue, 29 Nov 2011 18:27:23 UTC +00:00], ["url", nil],
["zip", nil]]
gem 'action_scaffold', :git => 'git://github.com/activescaffold/active_scaffold.git'
It's fixed in master, not released yet. Use :git =>
'git://github.com/active_scaffold/active_scaffold.git' or wait until it's
released
On Nov 30, 1:34 am, Sergio Cambra <ser...@entrecables.com> wrote:
> On Martes, 29 de noviembre de 2011 10:31:26 Kyle escribió:
>
> > Updated active_scaffold gem to 3.1.10 and still seeing the same
> > problem. Here's the log traffic showing the issue when creating a new
> > org selecting the same parent Program:
>
> It's fixed in master, not released yet. Use :git =>
> 'git://github.com/active_scaffold/active_scaffold.git' or wait until it's
> released
>
>
>
>
>
>
>
>
>
> > Started POST "/organizations" for 127.0.0.1 at 2011-11-29 11:27:23
> > -0700
> > Processing by OrganizationsController#create as JS
> > Parameters: {"utf8"=>"✓", "authenticity_token"=>"f2SgrBTEMh9JupF
> > +jXiZtrSy77Rf0ifXk+EOM7PmEhk=", "record"=>{"name"=>"Org 3",
> > "email"=>"kyle.cam...@gmail.com", "address_1"=>"", "address_2"=>"",
> > "city"=>"", "phone"=>"", "state"=>"", "url"=>"", "zip"=>"",
> > "program"=>{"name"=>"Demo", "description"=>"Demo program", "id"=>"1"},
> > "products"=>{"1322591204075"=>{"name"=>"", "description"=>""}}},
> > "associated_id"=>"1", "commit"=>"Create"}
> > Program Load (0.1ms) SELECT "programs".* FROM "programs" WHERE
> > "programs"."id" = ? LIMIT 1 [["id", "1"]]
> > Organization Load (0.2ms) SELECT "organizations".* FROM
> > "organizations" WHERE "organizations"."program_id" = 1
>
> > Here's where it sets all existing organization.program_id values to
> > NULL ...WHY??
>
> > SQL (0.5ms) UPDATE "organizations" SET "program_id" = NULL WHERE
> > "organizations"."program_id" = 1 AND "organizations"."id" IN (1)
>
> > After that now it creates the new org...
>
> > SQL (45.0ms) INSERT INTO "organizations" ("address_1", "address_2",
> > "city", "created_at", "email", "name", "phone", "program_id", "state",
> > "updated_at", "url", "zip") VALUES
> > (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["address_1", nil],
> > ["address_2", nil], ["city", nil], ["created_at", Tue, 29 Nov 2011
> > 18:27:23 UTC +00:00], ["email", "kyle.cam...@gmail.com"], ["name",