search for: find_or_create

Displaying 14 results from an estimated 14 matches for "find_or_create".

2007 Mar 16
1
Polymorphic find_or_create bug
Today I just spent 3 hours (and before a demo!) trying to figure out why my polymorphic association fields were breaking. Turns out someone else put in a patch for this 6 months ago. I''m not sure if its the same solution I''d use... I''d rather find_or_create attempt to use AssociationProxy#build if its available and only Base#new if we''re not on a proxy. http://dev.rubyonrails.org/ticket/4645 Can someone on core look at this. I can do another version if anyone would prefer. But, I''d love to have this fixed. Thanks, Hampton. --~--~...
2010 Jul 12
0
[Patch][Issue #5097] attributeless find_or_create/find_or_initialize
This patch relaxes DynamicFinderMatch to recognize find_or_create / find_or_initialize without a trailing _by_attribute_list. I''ve found this useful when the relevant attributes have already been built up through a chain of associations or named scopes. Please review, thank you! -- You received this message because you are subscribed to the Google Gr...
2009 Oct 11
0
Nested Attributes and find_or_create
...has_and_belongs_to_many relationships with the model I am trying to edit. Unfortunately when I add a new nested attribute, it creates a new row in the database. I need it to check up and determine if there is already a nested attribute of the same name first. Is this possible? I am exploring the find_or_create dynamic finder but I cannot figure out how to integrate it with the nested attributes. Thanks very much for your time -- Posted via http://www.ruby-forum.com/.
2006 Aug 02
1
ActiveRecord: find_or_create with has_and_belongs_to_many --
I am attempting to use find_or_create on a foreign table with a has_and_belongs_to_many relationship with my current table. I am doing the following: term = school.terms.find_or_create_by_code("FALL06") the queries in the log show the expected SELECT statement to query if there is a join table record between the school and...
2010 Mar 13
6
Find first or create
Is there any ActiveRecord''s dynamic finder that can allow me to find first association or create it if it doesn''t exist. Something like this (not this code is conceptual - it does not work!): Comment.posts.find_or_create(:first) -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this g...
2012 Feb 22
3
Parent id for find_or_create method
...o_id => @video.id)} %> which works fine. Now I would like to develop further. The Script objects may have already existed and if so, I want to update after editing them. So I tried, <%= render :partial => "create_or_update_script", :locals => { :script => Script.find_or_create_by_video_id(:video_id => @video.id)} %> renders a partial, <%= form_for script, :url=>{:controller=>''scripts'', :action=>''create_or_update''}, :remote => true do |f| %> <%= f.hidden_field :video_id %> <%= f.text_fiel...
2006 Feb 24
6
Duplicate entry - how to check if an id exist before saving?
How do I check if an entry exists before saving? Someone one told me to use the method find_or_create (or something like that) but it didn''t work because I think the version of rails that we have is not the most recent. I need a way to check if an id exists in the db before saving. Any suggestions? Thank you -- Posted via http://www.ruby-forum.com/.
2012 Jul 24
4
Behavior of first_or_create
I just ran across a weird glitch (IMHO) in find_or_create. The arguments passed to it are *not* added to the conditions for the ''first'' part. This is odd, given that it''s intended to replace find_or_create_by_* methods, which *did* use the specified values as conditions. I''m unsure on whether this behavior is entirely...
2006 Aug 14
1
Relationship not saving
...Base has_many :gifts ... class Gift < ActiveRecord::Base belongs_to :product_image ... I''m trying to associate an image with a gift, and for the life of me ActiveRecord will not associate them. Here is some test code and the associated output: gift.product_image = ProductImage.find_or_create(<some params>) p "PRODUCT IMAGE IS: #{gift.product_image}" gift.product_image.save p "PRODUCT IMAGE IS: #{gift.product_image}" gift.save p "PRODUCT IMAGE IS: #{gift.product_image}" gift.reload p "PRODUCT IMAGE IS: #{gift.product_image}&q...
2005 Jun 02
1
Populating Data on a Foreign Table
the scenario... three tables, thusly: widgets ------- id widget_color_id widget_style_id widget_colors ------------- id color widget_style ------------ id style the data: widgets ------- 1 2 1 2 1 3 3 3 2 widget_colors ------------- 1 blue 2 red 3 green widget_styles ------------- 1 smooth 2 round 3 broken so, putting the associations together, we have in widgets: 1 red smooth 2 blue
2012 Jan 04
1
AR update / create pattern: is there an easier way?
...ord.where(:attr1 => c.attr1, :attr2 => c.attr2, ...) c.save! unless r.exists? ... which has the effect of writing c to the db only if it is unique across the given attributes. Question: Do either of these forms replicate functionality already provided by ActiveRecord? (I know about the find_or_create dynamic methods, but those get unwieldy with more than two attributes.) Is there a cleaner or more idiomatic way? - ff -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this...
2008 Feb 08
4
x-post : find_or_initialize_by ActiveRecord bug? Ignores :conditions
....find_by_user_name is actually Person.find_by_user_name(user_name, options). So you could call Payment.find_all_by_amount(50, :order => "created_on"). The same dynamic finder style can be used to create the object if it doesn''t already exist. This dynamic finder is called with find_or_create_by_ and will return the object if it already exists and otherwise creates it, then returns it." Here are a couple of examples. I know these are contrived since I could use ''find_or_initialize_by_name_and_state()'' however what I am really trying to show is that the :conditio...
2012 Sep 20
2
Voicemail not working with vm boxes named with a star
Hi list, in asterisk 1.4 and maybe earlier it was possible to use voicemail system with mailboxes starting with some special characters like *. The line in voicemail.conf was like this: *123 => , AB,,,tz=cet|attach=no| Calling exten => s,n,Voicemail(*123,su) is working in asterisk 1.4. In Asterisk 1.8 the above scenario is not working any more. The Voicemail application reports an
2006 May 22
6
existing magic to prevent db redundancy?
suppose users have a favorite colour, linked to with a color_id field. suppose also they have a pet rock, which is one of many possible colors... is there a ''best practice'' in order to avoid having ''blue'' appear in the Color table 100 times. can validates_uniqueness_of be twisted into handling this case? should i be adding something to the initialize()