List Info

Thread: Nitro/Og Fora daily diggest




Nitro/Og Fora daily diggest
country flaguser name
United States
2007-04-03 03:41:20
>From rmela.myopenid.com 
Date: Mon Apr 02 00:55:49 UTC 2007
Subject: RE: 
In-Reply-To: http://www.nitroproject.org/fora/posts/view/bI
xv4i4dar27Z_eJeZaaqU
Message-ID: http://www.nitroproject.org/fora/posts/view/dM
ckJM4lqr27Z_eJeZaaqU

Could you point me to the source files and intended uses?

>From rmela.myopenid.com 
Date: Mon Apr 02 01:45:07 UTC 2007
Subject: Double inserts in admin/og/controller
Message-ID: http://www.nitroproject.org/fora/posts/view/dj
u_Ju4lSr27Z_eJeZaaqU

<Via admin/Og I create a new object of class
"Author".   Clicking "Save" results in
two records being saved to the ogauthors table, one with
null fields, one with values I've entered.

For the record:

class Author
   :attr_accessor first_name, String
   :attr_accessor middle_name, String
   :attr_accessor last_name, String
   def to_s
      last_name
   end
end

Here's the console output of a save to datastore.  Perhaps
the second save would result in an insert if oid were not
null?

DEBUG: SELECT COUNT(*) AS COUNT FROM ogauthor
DEBUG: INSERT INTO ogauthor (first_name, middle_name, oid,
last_name) VALUES (NULL, NULL, NULL, NULL)
DEBUG: INSERT INTO ogauthor (first_name, middle_name, oid,
last_name) VALUES ('Thomas', '', NULL, 'Jefferson')
DEBUG: SELECT COUNT(*) AS COUNT FROM ogauthor
DEBUG: SELECT * FROM ogauthor LIMIT 20

Commenting out lines 203-205 of og/lib/og/model.rb
(Og::Model::create) suppresses insertion of the blank
record.   The non-blank record is saved on line 106 of
nitro/lib/nitro/part/admin/controller.rb (
OgAdminController.save ).

Maybe the flaw is simply blank oids, and that initializing
an oid would result in an update to the existing record
rather than a save of a new record.

Still, I wonder -- should  Og::Model.create should be
calling "save", or should it leave that up to the
client code?  It assumes there's an initialize method that
properly populates the object for saving, and that the
caller knows the correct order and number of parameters for
that method.  It also assumes that, after initialize, no
further processing needs to be performed before the record
may be saved.

Here's the offending code:

og/lib/og/model.rb:

    200     def create(*args)
    201       obj = self.new(*args)
    202       yield(obj) if block_given?
    203       ogmanager.with_store do |s|
    204         s.save(obj)
    205       end
    206       return obj
    207     end

Here's the innocent victim ( OgAdminController.save ):

     90   def save
     91     klass =
name_to_class(request['object_class_name'].to_s)
     92
     93     if oid = request['oid']
     94       obj = klass[oid.to_s]
     95       obj.assign(request, :assign_relations
=>< true)
     96     else
     97       obj = klass.create ##### invokes save on obj
before returning obj to caller ####
     98       obj.assign(request, :assign_relations =>
true)
     99     end
    100
    101     unless obj.valid?
    102       flash.concat :ERRORS, obj.errors
    103       redirect_to_referer
    104     end
    105
    106     obj.save ### but obj was already saved in
klass.create (and if oid is null????)  ####
    107
    108     redirect :list, :name, obj.class
    109   end


>From rmela.myopenid.com 
Date: Mon Apr 02 02:12:29 UTC 2007
Subject: RE: 
In-Reply-To: http://www.nitroproject.org/fora/posts/view/dj
u_Ju4lSr27Z_eJeZaaqU
Message-ID: http://www.nitroproject.org/fora/posts/view/cB
8j124l8r27Z_eJeZaaqU

<blockquote> 
One more note, after trying the same code in mysql instead
of sqlite.

Any save of a new object to datastore will result in a new
oid for the object.

Should the in-memory copy of the object should be updated
with the OID?  My initial thought is that it should.  If so,
is that the responsibility of the adapter?

</blockquote>




--
This mail is automatically generated from the http://nitroproject.org/
fora
digest robot. It presents the discussions in the fora during
the last 24 hours.
Do not reply to this email.
_______________________________________________
Nitro-general mailing list
Nitro-generalrubyforge.org
h
ttp://rubyforge.org/mailman/listinfo/nitro-general

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )