similar to: One To Many To Many

Displaying 20 results from an estimated 5000 matches similar to: "One To Many To Many"

2006 Feb 16
9
association not inserted automatically.
Hello, I am trying to write a sample application. I have class LineItem< ActiveRecord::Base belongs_to : order end && class Order < ActiveRecord::Base has_one :line_item end Now in the controller i am trying : def add @ord = Order.new(params[:ord]) @ord.line_item = LineItem.new(params[:lineitem]) if @ord.save redirect_to :action => ''list'' else render
2006 Jan 12
5
Question about using DISTINCT in ActiveRecord find method.
Hi, Am relatively new to the RoR world. My question is quite simple. I have a query like such: shipmentNumbers = Order.find_by_sql(["select distinct s.id from orders o, line_items li, shipment_lines sl, shipments s where o.number=? and o.id = li.order_id and li.id = sl.line_item_id and sl.shipment_id = s.id", number]) The above query works fine. I wanted to do the same query using
2013 May 14
5
Why joins queries make result readonly?
Are there any rationalies to make queries obtained by joining scope to be readonly? I read some old posts (pre-rails3) that joins adds additional columns to record so that ActiveRecord doesn''t know how to update that fields, but actually I don''t see that fields. For example I write model class Order < ActiveRecord::Base has_and_belongs_to_many :executors, class_name:
2006 Dec 07
2
Problem saving parent and children using belongs_to, class_name, and foreign_key
Hi, I have a real simple association setup here that''s just trying to: - Create a new PayjunctionOrder - Create some LineItem objects and assign them to the PayjunctionOrder - Save everything I''m using Rails Edge. ---- class PayjunctionOrder < ActiveRecord::Base has_many :line_items end ------------------ ---- class LineItem < ActiveRecord::Base belongs_to :order,
2009 Apr 01
3
Nil being coerced to float
I was doing this: @line_items = LineItems.find_all_by_invoice_id(params[:id]) @payments = Payments.find_all_by_invoice_id(params[:id]) @total = @line_items.sum{ |item| item.cost } @payment_total = @payments.sum{ |payment| payment.value } @balance = @total - @payment_total But when no payments had been made it was coming up with an error when trying to sum nil, so I did
2008 Sep 02
5
Appending a record to a table
Hi I''m not too sure how best to explain this but here goes! I am trying to write an appointment system. I have, through example, just about got the dynamics correct. Even tried to play with some table joins (and excuse me if I''ve used the incorrect terminlogy). But no matter what I try I can''t seem to get the following code to work. I have a cart filled with Treatment
2006 Jun 24
2
Migrations problem with Agile Rails book
I am following the instructions on Agile Web Development with Rails book "Iteratio E1: Capturing an Order" section. When I run the migrations I get the following error. rake db:migrate (in /Users/balaparanj/work/depot) -- execute("alter table line_items \n add constraint fk_line_item_products \n foreign key (product_id) references products(id)") rake
2008 Jan 19
1
Decimals are being converted to Bigdecimals!!!!!
Hi all, I''m working on a financial app, and have set up some columns in my tables as decimals with precision => 8 and scale => 2. My migration looks like: change_column :lineitems, :price, :decimal, :precision => 8, :scale => 2 change_column :payments, :amount, :decimal, :precision => 8, :scale => 2 I''ve run the migration and restarted the server. I
2006 Nov 22
1
Polymorphic Data Modelling Question
Hello, I am not sure of the best way to model this situation in Rails and would appreciate some guidance. An order can hold multiple line items. Each line item is for a certain number of any given product. There are four products, each in a different table because they have completely different attributes. So I have: Order - has many LineItems LineItem - belongs to an Order
2006 Apr 20
5
strange mysql problem
i have this model: class LineItem < ActiveRecord::Base belongs_to :quote end in the console: >>l = LineItem.create ActiveRecord::StatementInvalid: Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' , , , )'' at line 1: INSERT INTO line_items (`qty`, `quote_id`,
2005 Dec 14
9
Passing quantity in a shopping cart
I am using this line on my index.rhtml page to capture the quantity required of a particular item for a basic shopping cart app: <%= text_field ''line_item'', ''quantity'', {:size=>3} %> </td> but my next screen (a cart screen) doesn''t reflect what was entered in that text field when the item is added to the cart. That is,
2006 Jan 15
6
Saving one-many associations (elegant solution please)
What is the most elegant way to save new one-many associations? order = Order.new(:name => "My Order") order.line_items << LineItem.new(:product_id => 1, :quantity => 2) order.line_items << LineItem.new(:product_id => 2, :quantity => 5) order.save The above - which is by far the most elegant way of putting it - doesn''t work for me - the line_items
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
2006 May 02
4
Bug in rails ?
Hi ! I just have a simple question. I am writing an app using rails to familiarize myself with the framework (which is pretty cool, by the way). I just wanted to know why these two work differently (since "find" should be a synonym for "detect" according to the Pick Axe) : current_item = @invoice.line_items.detect {|i| i.product.id == key} current_item =
2003 Jan 08
2
Problem with fontsize of pie-chart in postscript file
Hi all, I've a problem with the size of the labels of my pie-charts when I try to write them to a postscript file. I need to increase the default size, so I change cex (see below). On screen this works fine, but cex doesn't seem to affect the postscript-file. Any suggestions? Thanks a lot, Daniel Copy/Past-example (will try to write to c:/temp!): labels <- c("I",
2006 Mar 29
2
Rake Migrations for Rails 1.1
Hi all. I keep having the following error when I invoke the rake db:migrate command for Rails 1.1 (Ruby 1.8.2 -- Windows 2000) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate == Realtorex: migrating ======================================================= -- create() rake aborted! undefined method `create'' for
2006 Mar 20
1
Running total of a field in child records
What is the best way to get the running total of a number field in child records. Let say I have an Order model, which has_many :line_items, and each LineItem has an amount field. I would like to get the grand total of a specific Order. Is it a good idea to add a ''total'' column in the ''orders'' table and update it every time a line_item is
2007 Jul 24
9
will_paginate plugin doesn't work with Association Extensions?
I have: class Post < ActiveRecord::Base has_many :comments do def published find( :all, :conditions => {:published => true} ) end end end When in my controller I do Post.find(:first).comments.published.paginate :page => params[:page] I get an error undefined method `paginate'' for []:Array Is will_paginate supposed to
2006 Jul 17
1
Updating multiple children from one page
Hello, I have a model called invoice and one called lineitem. An invoice has_many lineitems, and an lineitem belongs to an invoice. I have a model method that calculates the price of a lineitem, and one that calculates all lineitems in an invoice. I want to have an edit page that lists all the invoices lineitems and their calculated prices, with a text field for a person to change the
2006 Jul 08
4
Hidden fields in forms
Please can someone show me the correct syntax for a hidden field in forms, this is my code <%= start_form_tag :action => ''create'' %> <div class="form1"> <table width="auto" boader="8" cellspacing="5" cellpadding="5"> <% hidden_field ''line_item'', ''client_id'', :value