Displaying 20 results from an estimated 10000 matches similar to: "[Patch][Issue #5097] attributeless find_or_create/find_or_initialize"
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.
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 term with code
"FALL06":
SELECT * FROM term
INNER
2009 Oct 11
0
Nested Attributes and find_or_create
Hi,
I''m using the new Nested Attributes to edit my models. It''s a
complicated relationship between 5 different models which are subclassed
from a ''Metadata'' model. They all have 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
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:
2012 Feb 22
3
Parent id for find_or_create method
Rails 3.1.3
I have tables, Video and Script having association,
Video 1 --- n Script
So, every Script needs the parent id, in this case, video_id.
If I simply create a new Script instance, the view renders as follows.
<%= render :partial => "new_script", :locals => { :script =>
Script.new(:video_id => @video.id)} %>
which works fine. Now I would like to
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 undesirable, but it''s definitely
2010 Sep 13
0
unscoped option for associations?
Hi all,
I recently encountered a problem in my FriendlyId plugin where a
belongs_to association unexpectedly failed to load because a user was
using state_machine and a default scope to make only "active" records
return by default.
It seems logical to allow associations to be specifed as "unscoped" in
order to bypass any default scopes. Conceptually I see this as similar
to
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/.
2006 Aug 14
1
Relationship not saving
Hi All,
I have a one to many relationship between images and gifts (one image
can be assigned to multiple gifts):
class ProductImage < ActiveRecord::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
2012 Jan 04
1
AR update / create pattern: is there an easier way?
I find myself writing the following frequently:
r = MyActiveRecord.where(:attr1 => cond1, :attr2 => cond2, ...)
r.exists? ? r.first : r.create
... which has the effect of returning an instance of MyActiveRecord if
all the conditions are met, or creating one if it doesn''t. A variant of
this:
c = MyActiveRecord.new(:attr1 => val1, :attr2 => val2, ...)
r =
2017 Oct 03
2
Trouble when suppressing a portion of fast-math-transformations
>>> I'd like to emphasise in the latter one: "This option also relaxes the precision of
>>> commonly used math functions."
>>
>> Isn't this the "libm" flag that is proposed in this thread?
>
> I don't know. I didn't see any definition of it.
>
> In my case I'm talking about allowing the use of lower precision but
2010 Feb 11
3
Parameterized ActiveRecord Associations: Any such thing?
Hi list, how are ya?
So, my current project is just begging for the ability to have
parameterized associations in my ActiveRecord classes. Basically I
need something that is a cross between named scopes and standard
associations (has_many specifically).
I''m wondering if such a thing exists or, if not, if anyone else has an
elegant, equivalent solution?
Example:
class Sprocket <
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
2008 Aug 31
9
assigning collection values and exceptions
hi everyone,
I''ve this code in my Report model:
has_many :report_reasons, :validate => true
has_many :reasons, :through => :report_reasons #, :uniq => true
# :accessible => true
def reason_attributes=(reason_attributes)
reasons.clear
reason_attributes.uniq.each do |reason|
reasons << Reason.find_or_create_by_content(reason)
end
end
2008 Feb 19
1
[CruiseControl] RubyOnRails build 8896 failed
The build failed.
CHANGES
-------
Revision 8896 committed by bitsweat on 2008-02-19 02:56:05
Don''t assume all records from nested include are of same class. Closes #11154 [acechase]
M /trunk/activerecord/lib/active_record/association_preload.rb
A /trunk/activerecord/test/cases/associations/eager_load_nested_include_test.rb
TEST FAILURES AND ERRORS
-----------------------
Name:
2012 Aug 10
1
Merge scopes with OR
I''d be quite interested in a feature merging scopes with OR - currently the
default way is AND.
The feature seems to have been requested/reported here:
https://github.com/rails/rails/issues/5545
A pull request was sent, but it needs some work.
I wrote a quick attempt too here: https://gist.github.com/3312792
It uses the syntax:
Jobship.includes(:job).or(Jobship.accepted,
2017 Oct 04
2
Trouble when suppressing a portion of fast-math-transformations
> It might be clearer, instead of using 'libm', to use something like 'trans' (for transcendental functions).
That does seem clearer. ‘trans’ is definitely good with me.
-Warren
From: Hal Finkel [mailto:hfinkel at anl.gov]
Sent: Tuesday, October 3, 2017 5:13 PM
To: Ristow, Warren; Bruce Hoult
Cc: llvm-dev at lists.llvm.org
Subject: Re: [llvm-dev] Trouble when suppressing a
2007 May 31
0
Rails AR/SQLServer Unit Test: [6912] failed (but getting better)
"bitsweat" has given AR/SQLServer some love, but it''s still unhappy...
http://dev.rubyonrails.org/changeset/6912
------------------------------------------------------------------------
r6912 | bitsweat | 2007-05-31 10:15:56 -0700 (Thu, 31 May 2007) | 1 line
Fix an edge case with find with a list of ids, limit, and offset. Closes #8437.
2006 Jul 31
0
Patch for #3438: Eager loading doesn''t respect :order of associations
Hello all,
I still have a patch for #3438 (eager loading doesn''t respect
association orders); it passes all unit tests, and has additional unit
tests with full coverage. The patch is attached.
== The Bug ==
Author.find(1).posts != Author.find(1, :include => [:posts]).posts
if Author has_many :posts, :order => anything.
This means that either one must avoid eager loading or
2011 Apr 07
0
accepts_nested_attributes_for, validations, :inverse_of option on associations, and IdentityMap
This feels more like a question to ask the core list, forgive me if I trespass.
I''ve been trying to help one of my cow orkers get through a sticky
problem. He''s got a fairly complex nested form to update a model and
its children. He''s started adding some validations, and we''ve
encountered a number of issues:
First he had a validation on one of the child