similar to: Assigning has_many child in parent creation question

Displaying 20 results from an estimated 4000 matches similar to: "Assigning has_many child in parent creation question"

2006 Feb 09
2
Finding related items (like latent semantic indexing)
I''ve been trying to use Classifier::LSI to provide a means of finding ''related items'', where each item is a one line description of a product. Although on small samples the Classifier works great, it completely baulks on my current dataset of 3000 items. I''ve started to look at ferret this morning, following a post on the ruby mailing list. I''d
2005 Jul 25
2
acts_as_tree and traversing parent/child relationships
I am working on an Rails application that uses a pretty complex category structure through out the site. I have defined a table to house all the info and a FK to reference parents within the table CREATE TABLE categories ( id int(11) NOT NULL auto_increment, name varchar(50) NOT NULL, parent_id int(11) default NULL, constraint fk_category_id foreign key (category_id) references
2009 Feb 19
3
Associated child records not created on creation of a parent.
I am trying to create a record with association. Within the create method, I would also like to pre-populate dependent (has_many) records from a template in the database. The child records are <u>mysteriously rolled back </u> if I insert them in a loop. If I try to insert a single child record, it works.I have read the books and tried to google my way out of this but am at a dead
2006 Mar 10
8
multiple sub categories (parent-child)
hi. base from the cookbook example, where each categories can have many recipes, id like the categories to have multiple sub categories, unlimited levels. please show some code, as i am new to Ruby and Ruby On Rails. thanks -- Posted via http://www.ruby-forum.com/.
2006 Jul 13
1
How to create a child from a parent
Hi i am trying to figure out what is the best way to do this very basic thing: lets say i have two tables: one with parents and one with children. there is a one to many relation between them. I scaffolded the parents tabel and i can open each parent. Now i want to add a link to the ''show'' view which will create a new child record. In the model i defined the has_many and
2006 Apr 12
2
ActiveRecord Parent-Child relationship bug? config problem?
If i have a parent that has_many :children, and the child belongs_to :parent. Then when I add a new child to the parent like so: parent.children << Child.new, then shouldn''t the child also have a reference to the parent? but it doesn''t-- child.parent is nil-- what''s going on here? is this as it should be-- shouldn''t it have a reference to the
2006 Jul 20
3
sort_by with via a parent models child
I am having a problem with ruby''s sort_by function. I want to sort a list of parent model objects based on the children of the parent models. Normally you might say sortedList = modelList.sort_by { |model| model[''someAttribute''] } What I am tring to do is sortedList = modelList.sort_by{ |model| model.children.find(:first, order=>"price desc" ).price}
2006 Feb 23
3
has_many: inserting children when inserting parent
disclaimer: am in the midst of my first ruby/rails project I have a situation where I want several child records to be created when a new parent record is created. The following represents my first stab at coding it, am I on the right track? Here is the model: parents ---------- id name children ---------- id parent_id name class Parent < ActiveRecord::Base has_many: children end
2014 Nov 24
3
[PATCH] v2v: -i ova: Remove incorrect warning for disks that have no parent controller (RHBZ#1167302).
Don't assume every disk <Item> has a <Parent> field. For floppy disks this is not the case. Thanks: Junqin Zhou --- v2v/input_ova.ml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml index 95af2e5..9a9c10a 100644 --- a/v2v/input_ova.ml +++ b/v2v/input_ova.ml @@ -187,14 +187,17 @@ object for i = 0 to
2006 Feb 07
3
Creating a new object with a passed in parent?
I have a simple object, Article, which has_one :parent of the same time. On my Show page for a given article there will be a "new child" button which will pass the current :id (or the current Article itself) to the new form. What is the proper way to hide a reference to this parent in the form so that when it is submitted back, the create method knows what to do with it?
2006 Jul 04
1
Multiple parent ids
Hi, parent_id is the default name for the self-reference foreign key. What is the convention for naming the second parent id, the third? Thanks! gk -- Posted via http://www.ruby-forum.com/.
2006 Jun 07
2
destroy on has_many relationships.
i need to delete a record from the database and delete all of it''s children as well. is there a method for this? right now, i am finding all the children with the parent_id and destroying them first and then destroying the parent. seems like there would be a better way to do this but i can''t seem to figure it out. thanks, josh -- Posted via http://www.ruby-forum.com/.
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
2006 Apr 15
0
parent.children not updated (has_many)
Hi guys! class Parent < ActiveRecord::Base has_many :children end class Child < ActiveRecord::Base belongs_to :parent end I do: parent = Parent.find(1, :include => :children) parent.children.find(3).update_attribute(''name'', ''Tom'') (or parent.children.find(3).name = ''Tom'') parent.children.find(3).name => ''old
2006 Feb 27
1
How to build a recursive parenting structure?
I''m just getting used to using HABTM structures. Something I''m trying to do now is create a site that has "sections" each section then could have a sub "section". So I built a "sections" table and in the model I included the line "has_and_belongs_to_many :sections" I also made a table called "sections_sections" to build the
2008 Oct 09
2
has_many validation the Rails way
Okay, this is something I run into a lot and don''t really have a great solution. Here is a simple example: class Blog < ActiveRecord::Base has_many :posts validates_presence_of :name end class Post < ActiveRecord::Base belongs_to :blog validates_presence_of :name validates_presence_of :blog_id end Now, if I want to create a blog and post at the same time I
2004 Dec 29
2
Asterisk, she no hang uppa the phone!
I've been working on the local side of asterisk for several days, and I have the in-house dial plan pretty well corn fingered to my satisfaction. Today I began working on the other side to make asterisk do things like place an outgoing call to PSTN and route an incoming call from PSTN. I'm using a TDM11B with a single fxs and a single fxo. My analog handset is plugged into the port
2008 Jan 02
1
wants to get all parents with no children, etc
To all: hi, i have implemented the associations in my models so i have a Parent model that has many Children model but i need to get a list of Parents that do not have children or Parents that have just 2 children or Parents that have children whose name is ''James'', or ''Sarah'', or ''Betty'' or Parents whose children do not have names like
2006 Jun 03
2
Parent listing children.
My database is set up as Categories > Things associated by category_id and has_many and belongs_to. How would I go about listing all the categories and under each Category is it''s children? Is there an easy rails way to do this - preferably without using acts as tree? Any help is appreciated - thanks! -- Posted via http://www.ruby-forum.com/.
2005 Oct 26
1
acts_as_tree parent id problem
Hi all, I have a simple Category model which acts_as_tree. In the form partial, I use a select form helper to display all the categories so that the user can choose a parent category. This works fine, but when I submit the form, I get an AssociationTypeMismatch It seems that the parent id that I pass back into the controller is being treated as a String, rather than finding the appropriate