similar to: Turn of dependencies so that a destroy will not destroy chil

Displaying 20 results from an estimated 40000 matches similar to: "Turn of dependencies so that a destroy will not destroy chil"

2006 Mar 14
2
acts_as_paranoid and :include
Will the find from acts_as_paranoid filter down to an :include? For instance class parent acts_as_paranoid has_many: children end and class child acts_as_paranoid belongs_to :parent end Then if you Parent.find(:all, :include => children) you will get all the children if they are deleted or not. I guess the find that filters out the deleted_at is null does not filter down to the includes
2013 Jun 15
1
A puzzle about default_scope
Hi, guys I have a puzzle about default_scope. Suppose I have two model: class User < ActiveRecord::Base has_many :blogs default_scope where(deleted_at: nil) end class Blog < ActiveRecord::Base belongs_to :user end I want to produce sqlselect blogs.* from blogs inner join users on users.id = blogs.user_id and users.deleted_at is null And the code Blog.joins(:user), which I think
2006 Mar 24
6
Should counter_cache fields be saved in the database?
As far as I can tell, the counter_cache option on a belongs_to model doesn''t actually save anything in the database. For example, I have the following models: class Parent < ActiveRecord::Base has_many :children, :conditions => "deleted_at IS NULL" end class Child < ActiveRecord::Base belongs_to :parent, :counter_cache => true end With the following
2007 Jun 29
1
Speeding up :dependent => :destroy
I have a tree of models that represent a book. Looks like this: book sections documents paragraphs index entries glossary entries footnotes index entries glossary entries These are all models with has_many from parent and the child has belongs_to. They also all have dependent => :destroy
2007 Jun 13
6
ActiveRecord query using association
Hello all, I apologize if the answer to this question is going to be rudimentary, but I am thus far stymied by the information I have found on the web. This seems like it should be simple, but I haven''t really found an example of how to do this yet. I have a model called Account which has a belongs_to reference to another model, User, as below: class Account < ActiveRecord::Base
2007 Jan 08
2
Two problems with Acts_as_paranoid
Hi, I''ve run into two small problems with acts_as_paranoid and wondered if anyone else has experienced them as well (and if yes, if they have any solutions). 1. When using has_many :through, AAP doesn''t seem to take into account the fact that your join model might also be paranoid. My solution to this at the moment is to add an explicit conditions clause to the has_many
2007 Feb 05
6
Viewing object associated via "has_many :through"?
This is my first question to the Forum. I’ve set up these associations: class Playlist < ActiveRecord::Base … has_many :playlists_tracks, :dependent => :destroy has_many :track_ones, :through => :playlists_tracks, :source => :track has_many :track_twos, :through => :playlists_tracks, :source => :track end class Track < ActiveRecord::Base … has_many
2009 Oct 20
2
Find sub sub records
Hi everyone, I have the following problem, maybe someone can help me figure out what to do. To simplify my situation, I''m going to make an example of what I need, this is not the real app structure. Let''s suppose we have three models, Library, Author, Book. Manager has_and_belongs_to_many :area_managers AreaManager has_and_belongs_to_many :managers has_many :employees
2008 Apr 23
1
Validation dependent on unsaved parent
I''m having trouble with a validation that depends on an attribute of a belongs_to parent. If the child is added to an unsaved parent (parent.children << new child), the has_many collection parent.children includes the unsaved child. However the belongs_to attribute child.parent appears to be nil until the parent has been saved. Without access to the parent attributes, the validation
2008 Feb 22
4
has_many and belongs_to in rails 2.0.2 (child.Parent) is not working
Hi All I have 2 models working well in rails 1.2.6 : class TypeService < ActiveRecord::Base has_many :Services end class Service < ActiveRecord::Base belongs_to :TypeService end I was able to get the name of the service with Rails 1.2.3: s = Service.find(1) name_type_service = s.TypeService.name <<-- Now with rails 2.0.2 that doesn''t work With rails 2.0.2 s
2008 Oct 29
5
Polymorphic Associations with inheritance
I have two models, Article and Post, that has many Comments. However, both Article and Post are inherited from a BaseContent class like so: class Article < BaseContent has_many :comments, :as => :commentable end class Post < BaseContent has_many :comments, :as => :commentable end and here''s my Comment model: class Comment < ActiveRecord::Base belongs_to
2007 Aug 02
4
ActiveRecord Limitation (Advance)
Or is it ? Need to be able to :- @search = Form.find(:all, :include=>[:form_type, :form_type_items], :conditions=>....) I need in the Form model a :form_type_items, the question is, what is the relationship type? Current Models:- Form belongs_to :form_type FormType has_many :form_types has_many :form_type_items FormTypeItem Belongs_to :form_type Form ---------------- | id |
2008 Jan 21
13
has_many with different primary key
I''ve got quite the ActiveRecord challenge, any help would be appreciated. In my current project Companies can have many reviews. class Company < ActiveRecord::Base has_many :reviews, :as => :reviewable end However, my company table, I have two different IDs to identify my company. id - This is the typical id we use for normal stuff other_company_id - This is the id we use
2008 Feb 15
3
Destroy, dependent and performance
Hi! This is my first post in this forum. I''m learning RoR for two weeks and I''m very interested about how to improve this framework. I was testing one app I''m working in and I had some problems with destroying. The code is simple (and maybe wrong, as I said i''m just learning!). When you destroy a league, you send a message to all the users associated to this
2008 Feb 13
4
Migration Issues: Can't update newly added column values
Hello everyone, just wondering if anyone can help me with a migrations question here. Using: rails 2.0.2 ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin] mysql 5.0.45 Platform: windows xp The problem: ---------- I created a migration that is designed to add a column named "deleted_at" (timestamp) and then remove a column named "is_deleted" (boolean). The idea is to
2007 Oct 18
4
Polymorphic Association?
Hi there- I''m a newbie to this board, RoR, and web development in general. So please forgive me if this is in the wrong place or if the solution is really simple... I''m trying to conceptualize the relationships between a series of models for a page creation function. What I''d like is to have a Content Page which consists of a series of Content Blocks. The Content
2007 Sep 05
8
Hi..Guys new plugin again
Hi.. Guys new plugin again Foreign Key Associations is a plugin that automatically creates associations based on foreign-keys. The associations are created at runtime-ie. as your ActiveRecord models are loaded-so they will always be up-to-date. For example, given a foreign-key from a customer_id column in an orders table to an id column in a customers table, the plugin creates:
2006 Nov 27
3
ActiveRecord: Reference same table twice
Hi, I have 2 tables, "users", and "user_comments". I am trying to allow users to leave comments on each other''s profiles (eg, think youtube like this: http://www.youtube.com/profile_comment_all?user=google). Here is a simplified view of my database schema: mysql> describe users; +-----------------+--------------+------+-----+---------+----------------+ | Field
2010 Aug 19
4
implementing project management and event types
I am implemented a simple project management application. Each project has various events, and each event can be a different type. Some event information is common, such as name, start date, close date, and comments. I have a projects table which has_many events. My plan is to have several sub-event tables, like event_get_access which will contain an event_id field to link it to table events as
2006 Nov 26
5
associations help?
I have Users who can "own" Projects. There is only one owner. Users in general can be authorized to view certain projects. Here is my initial stab at this: class User < ActiveRecord::Base has_many :projects # ownership has_many :project_viewers, :dependent => :destroy has_many :projects, :through => :project_viewers, :uniq => true ... end class