Steven Garcia | 1 May 2011 17:07
Picon

Weird validation error on decimal fields

Given a model with the following field:

  
  property :price, Decimal, :precision => 10, :scale => 2

When I submit the form with a blank :price field, I get a validation error "must be a number"

Thing is I am not validating the presence of this field, shouldnt it only perform that validation if the field is required??

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
ghedamat | 1 May 2011 16:35
Picon
Gravatar

Re: Deprecate Warnings on dm-do-adapter

Same here...

I'm using padrino and bundler

seems that
the fresh padrino install i've made today
uses
data_objects (0.10.4) as a dm-do-adapter dependency

older padrino project uses data_objects (0.10.2) that seems to work...

any hints?

Thank you very much :)

On Apr 30, 8:09 pm, Israel Ben Guilherme Fonseca
<israel....@...> wrote:
> Well, maybe it is a noob question but, I made a fresh install of ruby and
> datamapper, and now i'm getting deprecation warnings whenever I execute a
> code with datamapper:
>
> I did exactly this after installing ruby 1.9.1:
>
> gem1.9.1 install data_mapper
> gem1.9.1 install dbi
> gem1.9.1 install dbd-pg
> gem1.9.1 install dm-postgres-adapter-1.1.0
> gem1.9.1 install pg
>
> (btw, whats the difference of pg and dbd-pg?)
>
> I got this error when executing a code:
>
> /usr/lib/ruby/gems/1.9.1/gems/deprecated-2.0.1/lib/deprecated.rb:199:
> warning: already initialized constant Deprecate
> DataObjects::URI.new with arguments is deprecated, use a Hash of URI
> components
> (/usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:231:in
> `new')
>
> This is my gem list:
>
> addressable (2.2.5)
> bcrypt-ruby (2.1.4)
> data_mapper (1.1.0)
> data_objects (0.10.4)
> dbd-pg (0.3.9)
> dbi (0.4.5)
> deprecated (2.0.1)
> dm-aggregates (1.1.0)
> dm-constraints (1.1.0)
> dm-core (1.1.0)
> dm-do-adapter (1.1.0) << The warning come from here
> dm-migrations (1.1.0)
> dm-postgres-adapter (1.1.0)
> dm-serializer (1.1.0)
> dm-timestamps (1.1.0)
> dm-transactions (1.1.0)
> dm-types (1.1.0)
> dm-validations (1.1.0)
> do_postgres (0.10.4)
> fastercsv (1.5.4)
> json (1.4.6)
> pg (0.11.0)
> stringex (1.2.1)
> uuidtools (2.1.2)

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

ghedamat | 1 May 2011 16:47
Picon
Gravatar

Re: Deprecate Warnings on dm-do-adapter

Updates on this issue
I'm having same issue here
I've started a new padr

looking at an older project it seems that using

    data_objects (0.10.3)

till version 0.10.3 does not raise the warning and everything works..

using version 0.10.4 (pulled by bundle update on a new padrino
project)

the warning appears and also the application is not able to work if
I'm using more than one model..

I'm kinda of a datamapper n00b so maybe I'm just doing something
wrong..

I think that i should write my setup in another way ( I suppose ) but
I can't get how this is supposed to work..

DataObjects::URI.new with arguments is deprecated, use a Hash of URI
components (/usr/local/rvm/gems/ruby-1.9.2-p136/gems/dm-do-
adapter-1.1.0/lib/dm-do-adapter/adapter.rb:231:in `new')

If you like I can post a couple of snippets of my code..

thank you for your great help

Mattia

On Apr 30, 8:09 pm, Israel Ben Guilherme Fonseca
<israel....@...> wrote:
> Well, maybe it is a noob question but, I made a fresh install of ruby and
> datamapper, and now i'm getting deprecation warnings whenever I execute a
> code with datamapper:
>
> I did exactly this after installing ruby 1.9.1:
>
> gem1.9.1 install data_mapper
> gem1.9.1 install dbi
> gem1.9.1 install dbd-pg
> gem1.9.1 install dm-postgres-adapter-1.1.0
> gem1.9.1 install pg
>
> (btw, whats the difference of pg and dbd-pg?)
>
> I got this error when executing a code:
>
> /usr/lib/ruby/gems/1.9.1/gems/deprecated-2.0.1/lib/deprecated.rb:199:
> warning: already initialized constant Deprecate
> DataObjects::URI.new with arguments is deprecated, use a Hash of URI
> components
> (/usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapter.rb:231:in
> `new')
>
> This is my gem list:
>
> addressable (2.2.5)
> bcrypt-ruby (2.1.4)
> data_mapper (1.1.0)
> data_objects (0.10.4)
> dbd-pg (0.3.9)
> dbi (0.4.5)
> deprecated (2.0.1)
> dm-aggregates (1.1.0)
> dm-constraints (1.1.0)
> dm-core (1.1.0)
> dm-do-adapter (1.1.0) << The warning come from here
> dm-migrations (1.1.0)
> dm-postgres-adapter (1.1.0)
> dm-serializer (1.1.0)
> dm-timestamps (1.1.0)
> dm-transactions (1.1.0)
> dm-types (1.1.0)
> dm-validations (1.1.0)
> do_postgres (0.10.4)
> fastercsv (1.5.4)
> json (1.4.6)
> pg (0.11.0)
> stringex (1.2.1)
> uuidtools (2.1.2)

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Piotr Solnica | 1 May 2011 17:55
Picon

Re: Deprecate Warnings on dm-do-adapter

This deprecation warning is silenced in DataMapper 1.1.1 which will be
released within the next few days.

Cheers

# solnic

On May 1, 4:35 pm, ghedamat <thama...@...> wrote:
> Same here...
>
> I'm using padrino and bundler
>
> seems that
> the fresh padrino install i've made today
> uses
> data_objects (0.10.4) as a dm-do-adapter dependency
>
> older padrino project uses data_objects (0.10.2) that seems to work...
>
> any hints?
>
> Thank you very much :)
>
> On Apr 30, 8:09 pm, Israel Ben Guilherme Fonseca
>
>
>
> <israel....@...> wrote:
> > Well, maybe it is a noob question but, I made a fresh install of ruby and
> > datamapper, and now i'm getting deprecation warnings whenever I execute a
> > code with datamapper:
>
> > I did exactly this after installing ruby 1.9.1:
>
> > gem1.9.1 install data_mapper
> > gem1.9.1 install dbi
> > gem1.9.1 install dbd-pg
> > gem1.9.1 install dm-postgres-adapter-1.1.0
> > gem1.9.1 install pg
>
> > (btw, whats the difference of pg and dbd-pg?)
>
> > I got this error when executing a code:
>
> > /usr/lib/ruby/gems/1.9.1/gems/deprecated-2.0.1/lib/deprecated.rb:199:
> > warning: already initialized constant Deprecate
> > DataObjects::URI.new with arguments is deprecated, use a Hash of URI
> > components
> > (/usr/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.1.0/lib/dm-do-adapter/adapte r.rb:231:in
> > `new')
>
> > This is my gem list:
>
> > addressable (2.2.5)
> > bcrypt-ruby (2.1.4)
> > data_mapper (1.1.0)
> > data_objects (0.10.4)
> > dbd-pg (0.3.9)
> > dbi (0.4.5)
> > deprecated (2.0.1)
> > dm-aggregates (1.1.0)
> > dm-constraints (1.1.0)
> > dm-core (1.1.0)
> > dm-do-adapter (1.1.0) << The warning come from here
> > dm-migrations (1.1.0)
> > dm-postgres-adapter (1.1.0)
> > dm-serializer (1.1.0)
> > dm-timestamps (1.1.0)
> > dm-transactions (1.1.0)
> > dm-types (1.1.0)
> > dm-validations (1.1.0)
> > do_postgres (0.10.4)
> > fastercsv (1.5.4)
> > json (1.4.6)
> > pg (0.11.0)
> > stringex (1.2.1)
> > uuidtools (2.1.2)

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

none1 | 1 May 2011 23:03
Picon
Gravatar

JSON - Backbone.js

I'm working through a basic demo of a backbone.js (derived from
http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/).
All examples I've found work with Activerecord.

It is very basic, but doesn't work when I recreate it using DM. I'm
new to js, but from what I can see the js is working but I haven't set
DM and rails to talk properly with the json coming from the browser:

The controllers below:

class DocumentsController < ApplicationController

  def create
  21-->   document = Document.create! params
    render :json => document
  end

end

Submitting a post to create:

 Processing by DocumentsController#create as JSON
  Parameters: {"title"=>"asdfasdf", "body"=>"asdfadsfs"}
Completed   in 1ms

ArgumentError (The attribute 'action' is not accessible in Document):
  app/controllers/documents_controller.rb:21:in `create'

 If I create objects through the console, they don't get rendered
either and there is js errors indicating not being able to read the
response correctly.

I've found next to nothing about backbone/dm and I'm new to js/json.
I'd like to be able to move what I'm doing into more of an ajax
context, and found backbone.js to be something I can understand. The
post doesn't give anything I'm accustomed to from a regular form (e.g.
params[:document], but I haven't toyed with the form template itself
yet hmmmm). Do I need to work with dm-serializer, there is something I
need to do to the model, etc.?

example application here:

https://blueblank-9UaJU3cA/F/QT0dZR+AlfA <at> public.gmane.org/blueblank/dmbackbone-example.git

Any input appreciated. I'd like to be able to work this out and have
others be able to reference.

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Piotr Solnica | 2 May 2011 11:20
Picon

Re: JSON - Backbone.js

Hi,

You should put document's params under :document key so you pass
params[:document] to #create method. What happens in your case is that
you pass entire params hash to #create which also includes :action
name (which is hidden in the logs, but it is there).

Also if you're using #create! all hooks are bypassed which includes
validations, you probably want to call #create instead.

Hope this helps

Cheers

# solnic

On May 1, 11:03 pm, none1 <matt.ge...@...> wrote:
> I'm working through a basic demo of a backbone.js (derived fromhttp://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by...).
> All examples I've found work with Activerecord.
>
> It is very basic, but doesn't work when I recreate it using DM. I'm
> new to js, but from what I can see the js is working but I haven't set
> DM and rails to talk properly with the json coming from the browser:
>
> The controllers below:
>
> class DocumentsController < ApplicationController
>
>   def create
>   21-->   document = Document.create! params
>     render :json => document
>   end
>
> end
>
> Submitting a post to create:
>
>  Processing by DocumentsController#create as JSON
>   Parameters: {"title"=>"asdfasdf", "body"=>"asdfadsfs"}
> Completed   in 1ms
>
> ArgumentError (The attribute 'action' is not accessible in Document):
>   app/controllers/documents_controller.rb:21:in `create'
>
>  If I create objects through the console, they don't get rendered
> either and there is js errors indicating not being able to read the
> response correctly.
>
> I've found next to nothing about backbone/dm and I'm new to js/json.
> I'd like to be able to move what I'm doing into more of an ajax
> context, and found backbone.js to be something I can understand. The
> post doesn't give anything I'm accustomed to from a regular form (e.g.
> params[:document], but I haven't toyed with the form template itself
> yet hmmmm). Do I need to work with dm-serializer, there is something I
> need to do to the model, etc.?
>
> example application here:
>
> https://bluebl...-9UaJU3cA/F/QT0dZR+AlfA <at> public.gmane.org/blueblank/dmbackbone-example.git
>
> Any input appreciated. I'd like to be able to work this out and have
> others be able to reference.

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

none1 | 2 May 2011 18:51
Picon
Gravatar

Re: JSON - Backbone.js

The form is coming from a javascript template....so it isn't strictly
the usual rails form:

<form>
    <label for='title'>Title</label>
    <input name='title' type='text' />

    <label for='body'>Body</label>
    <textarea name='body'><%= model.get('body') %></textarea>

    <button><%= model.isNew() ? 'Create' : 'Save' %></button>
</form>

also everything worked fine for the activerecord version....the model
had some function:

 def to_json(options = {})
    super(options.merge(:only => [:id, :title, :created_at, :body]))
  end

that does nothing with the dm version (that I can tell or register
atm)...and it is not just the form.

Console created documents aren't rendered in the collection with
another type of error:

WITHOUT dm-serializer:
-------------------------------------
Processing by DocumentsController#index as JSON
  SQL (0.164ms)  SELECT "id", "title", "body" FROM "documents" ORDER
BY "id"
Completed   in 25ms

NoMethodError (undefined method `encode_json' for #<Document  <at> id=1
 <at> title="none"  <at> body="asdfadfadsfasf">):
  app/controllers/documents_controller.rb:6:in `block (2 levels) in
index'
  app/controllers/documents_controller.rb:5:in `index'

WITH dm-serializer
---------------------------
Started GET "/documents" for 127.0.0.1 at 2011-05-02 12:46:26 -0400
  Processing by DocumentsController#index as JSON
  SQL (0.124ms)  SELECT "id", "title", "body" FROM "documents" ORDER
BY "id"
Completed 200 OK in 5ms (Views: 4.2ms | Models: 0.124ms)

.....and nothing

There is something I need to be doing that I don't know I need to be
doing to get the json in tune with dm -- my thoughts right now. I'll
just reiterate that the only change I made was swapping out all the
activerecord related code for dm related code.

On May 2, 5:20 am, Piotr Solnica <piotr.soln...@...> wrote:
> Hi,
>
> You should put document's params under :document key so you pass
> params[:document] to #create method. What happens in your case is that
> you pass entire params hash to #create which also includes :action
> name (which is hidden in the logs, but it is there).
>
> Also if you're using #create! all hooks are bypassed which includes
> validations, you probably want to call #create instead.
>
> Hope this helps
>
> Cheers
>
> # solnic
>
> On May 1, 11:03 pm, none1 <matt.ge...@...> wrote:
>
> > I'm working through a basic demo of a backbone.js (derived fromhttp://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by...).
> > All examples I've found work with Activerecord.
>
> > It is very basic, but doesn't work when I recreate it using DM. I'm
> > new to js, but from what I can see the js is working but I haven't set
> > DM and rails to talk properly with the json coming from the browser:
>
> > The controllers below:
>
> > class DocumentsController < ApplicationController
>
> >   def create
> >   21-->   document = Document.create! params
> >     render :json => document
> >   end
>
> > end
>
> > Submitting a post to create:
>
> >  Processing by DocumentsController#create as JSON
> >   Parameters: {"title"=>"asdfasdf", "body"=>"asdfadsfs"}
> > Completed   in 1ms
>
> > ArgumentError (The attribute 'action' is not accessible in Document):
> >   app/controllers/documents_controller.rb:21:in `create'
>
> >  If I create objects through the console, they don't get rendered
> > either and there is js errors indicating not being able to read the
> > response correctly.
>
> > I've found next to nothing about backbone/dm and I'm new to js/json.
> > I'd like to be able to move what I'm doing into more of an ajax
> > context, and found backbone.js to be something I can understand. The
> > post doesn't give anything I'm accustomed to from a regular form (e.g.
> > params[:document], but I haven't toyed with the form template itself
> > yet hmmmm). Do I need to work with dm-serializer, there is something I
> > need to do to the model, etc.?
>
> > example application here:
>
> > https://bluebl...-9UaJU3cA/F/QT0dZR+AlfA <at> public.gmane.org/blueblank/dmbackbone-example.git
>
> > Any input appreciated. I'd like to be able to work this out and have
> > others be able to reference.

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Ian MacLeod | 2 May 2011 20:20
Gravatar

Optimizing queries that use a join table

(Note: I've asked this same question on stack overflow if you want
some better syntax highlighting:
http://stackoverflow.com/questions/5808863/how-can-i-better-optimize-many-to-many-association-queries-with-datamapper)

DataMapper appears to be generating grossly sub-optimal queries for
associations that use a join table (whether I use :through =>
Resource, or an explicit join table). What can I do to improve the
performance of these queries?

Here's an example setup:

class Left
  include DataMapper::Resource

  property :id, Serial

  has n, :joins
  has n, :rights, :through => :joins
end

class Join
  include DataMapper::Resource

  belongs_to :left,  :key => true
  belongs_to :right, :key => true
end

class Right
  include DataMapper::Resource

  property :id, Serial

  property :one, String
  property :two, Integer
end

Now, say I have some data populated and I want to grab all the rights
associated with a left object (let's just use the first one for ease):
Left.first.rights

DataMapper executes the following query (MySQL):

SELECT rights.id, rights.one, rights.two
FROM rights
INNER JOIN joins ON rights.id = joins.right_id
INNER JOIN lefts ON joins.left_id = lefts.id
WHERE joins.left_id = 1
GROUP BY rights.id, rights.one, rights.two
ORDER BY rights.id

For one, the "INNER JOIN lefts ON joins.left_id = lefts.id" is
completely unnecessary.  I don't trust MySQL on this one, especially
since the explain plan gives a "Using index; Using temporary; Using
filesort".  Also, what's up with the GROUP BY rather than SELECT
DISTINCT?

Another option is to explicity query through the join table via
"Join.all(:left => Left.first).rights" or "Left.first.joins.rights".
Both of these result in two queries:

SELECT right_id FROM joins WHERE left_id = 1
SELECT id, one, two FROM rights WHERE id = 1 ORDER BY id

I haven't profiled this exact setup, but in all cases where I'm
following the same pattern, the first query is super slow (~100x
slower than than the two query method to a localhosted mysql
instance).

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

Clifford Heath | 2 May 2011 23:47
Picon

Re: Optimizing queries that use a join table

On 03/05/2011, at 4:20 AM, Ian MacLeod wrote:
> DataMapper appears to be generating grossly sub-optimal queries

There's very little wrong with those queries, but there is a lot wrong
with the MySQL optimiser. It's a heuristic optimiser, and every other
RDBMS discarded that approach around 1985. Please consider using
an RDBMS with a proper optimiser. Postgres is a good free option.

> What can I do to improve the performance of these queries?

You should index all foreign keys. That should get rid of the
temporary and sort in the query plan.

> For one, the "INNER JOIN lefts ON joins.left_id = lefts.id" is
> completely unnecessary.

No, it isn't. You've asked DataMapper for the first Left, and all
its Rights, and that's exactly what it's giving you. It has no way
to know that you aren't using the Left it loads for you.

Clifford Heath.

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.

RipTheJacker | 3 May 2011 00:38
Picon
Gravatar

Re: Help with a join

Datamapper stores objects in a hash so they don't get created multiple
times per request (see IdentityMap). It's a performance thing, so I'm
guessing that your other Ingredients are there because it wouldn't
make sense for DM to return the same thing twice. You can get the
results you want by doing this:

 <at> ingredients = Menu.first( :name => 'main').meals.collect{ |m|
m.ingredients }.flatten

That won't affect the performance much because DM will eager load the
'ingredients' for you, but it will still give you an array of what you
need (or an array of array's without the #flatten)

On Apr 30, 7:29 am, "J.D." <jeremym1...@...> wrote:
> I'm new to DataMapper and trying my best to learn and embrace it
> instead of resorting to SQL. In this particular situation I have a
> model with Menus, Meals and Ingredients. All set up with "has
> n, :XXX, :through => Resource".
>
> In one location I want to grab a Menu, and show all ingredients for
> all meals in that menu. The problem is if 2 meals reference "1 onion",
> for example. In that case DM is generating a join that only provides 1
> entry for "1 onion", but I expect two.
>
> I'm using:
>
>  <at> ingredients = Menu.first( :name => 'main').meals.ingredients.all
>
> I'm assuming I need to somehow modify my reference to the meals
> collection, but I can't seem to find where the documentation talks
> about this. Any pointers?
>
> J.D.
>
> Model for reference:
>
> class Meal
>   include DataMapper::Resource
>
>   property :id,     Serial  # autoinc
>   <snip>
>
>   has n, :ingredients, :through => Resource
>   has n, :menus, :through => Resource
> end
>
> class Ingredient
>   include DataMapper::Resource
>
>   property :id,       Serial
>   property :name,     String
>   <snip>
>
>   has n, :meals, :through => Resource
> end
>
> class Menu
>   include DataMapper::Resource
>
>   property :id,       Serial
>   property :name,     String
>
>   has n, :meals, :through => Resource
> end

--

-- 
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To post to this group, send email to datamapper@...
To unsubscribe from this group, send email to datamapper+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.


Gmane