search for: inverse_of

Displaying 12 results from an estimated 12 matches for "inverse_of".

2013 Feb 06
0
inverse_of breaks for unsaved child associations during save of parent
I''m willing to write a patch for this issue: https://github.com/rails/rails/issues/8893 But want to confirm that the new behavior makes sense before I make the effort. Essentially if you have an unsaved parent and child, and the parent''s association to the child has an inverse_of declared on it. When the parent gets saved, it updates the foreign key on the child, and this makes the association stale, breaking the inverse_of connection. It should be pretty easy to fix. Either on the parent''s side by checking to see if the association we''re setting the...
2013 Mar 30
1
How to use group in nested associations
The below query fails: Timesheet.joins(:time_entries).select("timesheets.*, sum(time_entries.worktime) as total").group("timesheets.start_date") The models have the following relations: Timesheet < AR has_many :activities, dependent: :destroy, inverse_of: :timesheet has_many :time_entries, through: :activities accepts_nested_attributes_for :activities, allow_destroy: true end class Activity < AR belongs_to :timesheet, inverse_of: :activities belongs_to :task has_many :time_entries, order: :workdate, dependent: :destroy, inverse_of: :...
2011 Mar 29
0
inverse_of not supported in Rails 3 for has_many?
...i-directional associations with has_many and belongs_to: # NOTE - for now, we''re only supporting inverse setting from belongs_to back onto # has_one associations. def we_can_set_the_inverse_on_this?(record) @reflection.has_inverse? && @reflection.inverse_of.macro == :has_one end Why wasn''t that implemented, it doesn''t seems much more difficult to implement than has_one and belongs_to. I''m running rails 3.0.5. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to th...
2011 Apr 07
0
accepts_nested_attributes_for, validations, :inverse_of option on associations, and IdentityMap
...of issues: First he had a validation on one of the child models which needed to be conditional on an attribute in the parent model. We realized that on a save, the child was fetching the parent from the database, and so was seeing the old value in the parent. This led me to the discovery of the :inverse_of option on :belongs_to and :has_xxx associations. Adding this option to both ends of the associations in question fixed the problem of the validation not triggering, and that''s when we noticed a second problem. Lets say we enter a value for an attribute of one of the child models, and vali...
2013 Mar 25
1
validates presence of foreign key fails in nested form
I''m using accepts_nested_attributes as follows: class Timesheet < ActiveRecord::Base attr_accessible :status, :user_id, :start_date, :end_date, :activities_attributes has_many :activities, dependent: :destroy has_many :time_entries, through: :activities accepts_nested_attributes_for :activities, allow_destroy: true end class Activity < ActiveRecord::Base attr_accessible
2011 Jan 11
0
Should set_inverse_instance be called earlier in add_record_to_target_with_callbacks ?
Right now when you add a record to an association with << it first saves the model, and THEN sets the inverse_of association afterward. This is done inside add_record_to_target_with_callback inside association_collection.rb. Is there any reason set_inverse_instance isn''t called before the save of the model? We are referencing the parent in our save callbacks, so we''re getting the parent (...
2012 Jan 18
2
Polymorphic and standard association issue
Hello all, I''m having a strange issue with a model that belongs_to two other models. The one association is polymorphic and the other is normal. ================================ class Role < ActiveRecord::Base belongs_to :user belongs_to :permission, :polymorphic => true end class User < ActiveRecord::Base has_many :roles has_many :programs, :through => :roles end
2010 Feb 08
5
Why are double sided polymorphic relationships lacking in Rails?
http://stackoverflow.com/questions/2224994/why-are-double-sided-polymorphic-relationships-lacking-in-rails -- 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 group, send email to
2010 Aug 18
11
When after_save isn't after the save....
I have a Production model, which represents a farmer''s crop. After create (via after_save) I call a method that creates one or more Supply models, which represent a week of anticipated product harvest. After each of those are created, a class method gets called that tries to match each new Supply with outstanding orders for the same time period. If a match is made, a transaction (an
2013 Feb 13
3
conditional validates_associated
Hello, Have you guys noticed that conditional validation with validates_associated does not work well when you are creating a new record? Consider this gist: https://gist.github.com/aflag/4780225 The Lawyer class has validates_associated on address conditioned on whether the Lawyer data comes from a known source or not. So, if lawyer.source equals to some string, then lawyer.address must
2013 Mar 26
0
nested forms: use validate :some_method works in update mode only
...:start_date, :end_date, :activities_attributes SUBMITTED = ''Submitted'' APPROUVED = ''Approuved'' REJECTED = ''Rejected'' STATUS_VALUES = [SUBMITTED, APPROUVED, REJECTED] belongs_to :user has_many :activities, dependent: :destroy, inverse_of: :timesheet has_many :time_entries, through: :activities accepts_nested_attributes_for :activities, allow_destroy: true validates :user_id, presence: true validates :status, presence: true, inclusion: {in: STATUS_VALUES} validate :maximum_worktime_per_day after_update :check_an_...
2012 Jun 08
7
filter children with acts_as_tree
Hello Experts, I have a tree of categories in this category object there is a property called type. the root categories have no type but the children have. so how I can get all the roots with filled in children that have category type = ''B'' for instance. I tried to run Category.roots then delete children With a category not equal to ''B'' but this causes a major