[DataMapper] Re: dm-types and Flag[]
Thanks for the reply but to be honest I'm not really sure as there appears to be some confusion, in my mind anyway, created by the example syntax on http://datamapper.org/docs/dm_more/types... however, I may of course be over complicating matters as well. Personally I would have thought firstly if it was a bitwise mapping, i.e., digit maps to a named value or key, and ideally once you've declared any base values, e.g. Flag[:admin, :editor, :translator, :tester], should be centrally controlled and fixed / restricted during any subsequent create or update actions and as such cannot then mutate. For example, :role type :nobody doesn't exist in the original list so should it still be accepted? Secondly, you shouldn't really be able to exceed the total number of initial values that you've specified (?), but it turns out that you can. These two questions arose from using the Flag[] type which, to be perfectly honest, I'm not sure if these are bugs or not, or just reasonable behavior... Anyway, as I needed to restrict the possible entries to only those I specified I added a validates_with_method to the model. This hopefully stops any deviation from the original list and contains the situation. This pastie shows the model and rspec tests for that stage of development which I had reached: http://pastie.org/1055304 So, that was all good once I added in my own validation, however, on adding a few rspec tests for the merb-auth backed authentication things became quite strange again. In order to successfully test the authentication, and have it return the pre-defined :role value I passed - which was part of the default set of valid credentials, without the :role value /disappearing/ I had to specify the roles explicitly in the model again, i.e., property :role, Flag[:admin, :editor, :translator, :tester] This pastie shows what I now have: http://pastie.org/1055330 I'm still none the wiser about what I can really expect from Flag[], although I see it as damned handy for this usage, and whether I've stumbled on bugs or not.. If this type of behavior for Flag[] suggests problems still please let me know and I'll fire off a bug report. On 22 July, 04:37, Kevin inspir...@gmail.com wrote: Ah, so flag assigns a bit to each flag and can add them together/etc to allow multiple flags to be set? Your failing test seems to be a bug with it, eh? Add a ticket to the lighthouse?http://datamapper.lighthouseapp.com/projects/20609-datamapper/overview -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] Re: Is it possible to create a duplicate of a record ?
... possibly a bit late for this, as Kevins answer is pretty much identical anyway :), but I found this damned handy - but at the time couldn't really find anything on this list to help before.. # get a record @item = Item.first # override original values where required @duplicate = @item.attributes.merge({ :id = nil, :type = 'duplicate', :created_at = DateTime.now }) .. You could also use the amazingly handy dm-is-self_referential [http:// github.com/snusnu/dm-is-self_referential] to say that the duplicate you're creating is a 'child' of the original, if you so wished.. I found this handy when specifying digital art prints that had both an obverse and reverse pictures printed, e.g. The reverse is a child of the obverse view :-) Hope that helps as well.. On 14 July, 07:59, wea_gruena aweber.gru...@googlemail.com wrote: Hi Kevin, thanks for your good idea. I've tried this: irb(main):001:0 require './db/config' = true irb(main):002:0 p1 = Profile.new = #Profile @name=nil @descr=nil @pmodule_name=nil @standard=nil @active=nil @delete=nil @created_at=nil irb(main):003:0 p1.name = 'TEST' = TEST irb(main):005:0 p1.pmodule_name = 'DESIGN' = DESIGN irb(main):006:0 p1.save = true irb(main):007:0 p2 = Profile.new = #Profile @name=nil @descr=nil @pmodule_name=nil @standard=nil @active=nil @delete=nil @created_at=nil irb(main):010:0 p2.attributes = p1.attributes = {:descr=nil, :pmodule_name=DESIGN, :active=false, :created_at=#DateTime: 21214585031031383/864000,1/12,2299161, :delete=false, :name= TEST, :standard=false} irb(main):011:0 p2.name = 'TEST_X' = TEST_X irb(main):012:0 p2.save = true irb(main):013:0 And it looks good. It's important to set the name (the key) AFTER p2.attributes = p1.attributes, then everything it's O.K. Thanks a lot again, Andreas On 14 Jul., 00:25, Kevin inspir...@gmail.com wrote: Maybe you could get it to work with p2.attributes = p1.attributes p2.id = nil # so that it gets the auto-increment value from the database/etc. p2.save Or use one of the strange hash.merge functions to combine your changes to the p1.attributes. Good luck! -Kevin On Jul 13, 6:20 am, wea_gruena aweber.gru...@googlemail.com wrote: Hi all, the newbie is back ;-( Is it possible to create a copy of a record like this: [code] p1 = Profile.first(:name = 'ABC') p2 = p1.duplicate(:name = 'DEF') p2.save [/code] What's the best way to solve this problem ? Is it possible to copy / duplicate also associations etc. ? Thanks, Andreas -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] Re: paranoiddatetime-and-paranoidboolean-fail-in-100
Hmmm.. No luck with getting around this at the moment with ParanoidDateTime in my model although dm-types is being loaded. As I said the usual suspect places for declaring any require statements within Merb fail to help here and there doesn't appear to be any Class conflicts with Type.. May fire this off to the Merb list as well to make sure I'm not just being dappy! On 21 July, 14:32, tenstates imdata...@googlemail.com wrote: Top man and cheers for the reply.. some homework for me tonight me thinks :) On 21 July, 00:08, Kevin inspir...@gmail.com wrote: Paranoia (at least when I was testing it) doesnt stop you from destroying the rows - it mostly just affects the getters to add and paranoiddeleted=0. So that @user.items only loads items where paranoiddeleted=0. You need to make your controller's destroy method set paranoiddeleted=1 instead of calling destroy to work with it. I this will let you talk to the datastore directly, though I haven't tested it much: DataMapper.repository(:default).adapter.execute(my sql) - use .select to get the result and turn it into structs, but doesnt work for updates/etc. Regarding the loading issue - maybe try referring to it as Types::ParanoidDateTime, though that shouldn't be required. Try making a testing.rb script that *just* loads datamapper and your models and see if it might be something in merb. The Types namespace might be used by something else? Good luck, Kevin -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] dm-types and Flag[]
Just been looking at the documentation for Flag within dm-types. I can see that the property of type Flag[] is assigned a type of integer in the DB. It appears you can assign additional values to those you specify by symbol as well as by overall amount of items. With that I was wondering what the original intent was for stating the properties values was if you can then add additional, non-stated, ones without it complaining? Yes, validation can sit in front of the various checks that may need to be made but I just wanted to clarify the reason for the example syntax first. Other than that a very useful addition to declaring properties :) property :role, Flag[:admin, :editor, :translator, :tester] rspec tests specify should be valid with :translator and :editor as :role do @model.attributes = valid_user_attributes @model.role = [ :translator, :editor ] @model.should be_valid end * PASS specify should be invalid with :anybody as :role do @model.attributes = valid_user_attributes @model.role = [ :anybody ] @model.should_not be_valid end * FAIL specify should be invalid when exceeding the original number of :role values do @model.attributes = valid_user_attributes @model.role = [ :admin, :editor, :translator, :tester, :anybody ] @model.should_not be_valid end * FAIL -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] Re: paranoiddatetime-and-paranoidboolean-fail-in-100
Top man and cheers for the reply.. some homework for me tonight me thinks :) On 21 July, 00:08, Kevin inspir...@gmail.com wrote: Paranoia (at least when I was testing it) doesnt stop you from destroying the rows - it mostly just affects the getters to add and paranoiddeleted=0. So that @user.items only loads items where paranoiddeleted=0. You need to make your controller's destroy method set paranoiddeleted=1 instead of calling destroy to work with it. I this will let you talk to the datastore directly, though I haven't tested it much: DataMapper.repository(:default).adapter.execute(my sql) - use .select to get the result and turn it into structs, but doesnt work for updates/etc. Regarding the loading issue - maybe try referring to it as Types::ParanoidDateTime, though that shouldn't be required. Try making a testing.rb script that *just* loads datamapper and your models and see if it might be something in merb. The Types namespace might be used by something else? Good luck, Kevin -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] paranoiddatetime-and-paranoidboolean-fail-in-100
Got this same issue but having difficulty tracking down where the require statement is placed in Merb? I've tried adding it to the usual places but the failure is still the same as this ticket below.. http://datamapper.lighthouseapp.com/projects/20609/tickets/1345-paranoiddatetime-and-paranoidboolean-fail-in-100 Had no problem with this and 0.10.3 so why isn't dm-types being loaded now? Also was there any reliable way of deleting all the records even with this paranoia in place, e.g. after each rspec test that uses a DB to store the data? Many thanks -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] dm-is-self_referential and namespacing
If I have a model stated as Admin::Assignments and add the following: is :self_referential, :through = 'AdminTask', :children = :child_tasks, # admin_child_tasks :parents= :parent_tasks, # admin_parent_tasks :source = :parent_tasks, # parent_tasks :target = :child_task # child_tasks both create_relationship_writer and create_relationship_reader in dm- core-0.10.3/lib/dm-core/model/relationship.rb fail because of the / in the relationship.name. I get the following error from : syntax error, unexpected '/', expecting '\n' or ';' def admin/assignment_child_tasks(query = nil) Can anyone suggest a patch for this? -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] Re: is :self_referential
Used this which only found parent records with children. self.all( :conditions = { :type = :duplicate } ).parent_items.each do | r | a.push r end On Apr 20, 5:28 pm, tenstates imdata...@googlemail.com wrote: Hi I had decided to usehttp://github.com/snusnu/dm-is-self_referential but am having trouble isolating records without children due to the absence of a foreign key in my model to map the values of the join table by. is :self_referential, :through = 'Publication', :children = :child_items, # item_child_items :parents = :parent_items, # item_parent_items :source = :parent_items, # parent_items :target = :child_item, # child_items :order = [ :published_at.desc ], :constraint = :destroy Is there a clean way to say something like this below but in reverse so as to only get back those results without children? I have tried a number of combination's, but really need some pointers. item = Item.all item.child_items.each { | child | item.object_id == child.parent_items.object_id } Thanks -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group athttp://groups.google.com/group/datamapper?hl=en. -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] is :self_referential
Hi I had decided to use http://github.com/snusnu/dm-is-self_referential but am having trouble isolating records without children due to the absence of a foreign key in my model to map the values of the join table by. is :self_referential, :through = 'Publication', :children= :child_items, # item_child_items :parents = :parent_items, # item_parent_items :source = :parent_items, # parent_items :target= :child_item, # child_items :order= [ :published_at.desc ], :constraint = :destroy Is there a clean way to say something like this below but in reverse so as to only get back those results without children? I have tried a number of combination's, but really need some pointers. item = Item.all item.child_items.each { | child | item.object_id == child.parent_items.object_id } Thanks -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
[DataMapper] Hmmm.. updating associated records
Hi all, I've seen the discussions on the update to datamapper and what is considered a dirty resource but still need to ask the following question. This is in relation to version 0.10.2 ... Here's a trimmed down version of the models I have. class Publication include DataMapper::Resource property :id, Serial property :published, Boolean, :default = false has 1, :asset end class Asset include DataMapper::Resource property :id, Serial property :title, String belongs_to :publication end I have nested fields for editing / Updating an Asset attributes, via the form, like this: publication[asset][...] which I use when making a new record. So..., when I want to update these records with any changes what is the best approach? I gather from trying and reading that @publication.update(publication) is no longer an option. Many thanks in Advance -- You received this message because you are subscribed to the Google Groups DataMapper group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.