This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order < ActiveRecord::Base | |
attr_accessible :client_id, :order_total | |
has_many :orderedproducts | |
has_many :products, through: :orderedproducts, :source => :product | |
has_one :client | |
before_save :generate_total | |
def generate_total | |
self.order_total = self.products.sum(:product_price) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order < ActiveRecord::Base | |
attr_accessible :client_id, :order_total, :delivery_date | |
has_many :orderedproducts | |
has_many :products, through: :orderedproducts, :source => :product | |
has_one :client | |
before_save :generate_total | |
def generate_total | |
self.order_total = self.products.sum(:product_price) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):023:0> order.save | |
(0.1ms) BEGIN | |
(0.2ms) SELECT SUM(`products`.`product_price`) AS sum_id FROM `products` INNER JOIN `orderedproducts` ON `products`.`id` = `orderedproducts`.`product_id` WHERE `orderedproducts`.`order_id` IS NULL | |
SQL (0.1ms) INSERT INTO `orders` (`client_id`, `created_at`, `delivery_date`, `order_total`, `updated_at`) VALUES (1, '2013-05-12 14:25:21', '2013-07-24', 0.0, '2013-05-12 14:25:21') | |
SQL (0.1ms) INSERT INTO `orderedproducts` (`created_at`, `order_id`, `product_id`, `quantity_ordered`, `updated_at`) VALUES ('2013-05-12 14:25:21', 6, 1, NULL, '2013-05-12 14:25:21') | |
SQL (0.1ms) INSERT INTO `orderedproducts` (`created_at`, `order_id`, `product_id`, `quantity_ordered`, `updated_at`) VALUES ('2013-05-12 14:25:21', 6, 2, NULL, '2013-05-12 14:25:21') | |
(47.8ms) COMMIT | |
=> true | |
irb(main):024:0> order.save | |
(0.1ms) BEGIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):005:0> order.save | |
(0.1ms) BEGIN | |
SQL (0.2ms) INSERT INTO `orders` (`ClientID`, `OrderTotal`, `created_at`, `updated_at`) VALUES (NULL, NULL, '2013-05-11 13:43:12', '2013-05-11 13:43:12') | |
(167.8ms) ROLLBACK | |
ActiveRecord::UnknownAttributeError: unknown attribute: order_id | |
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:88:in `block in assign_attributes' | |
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `each' | |
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/attribute_assignment.rb:78:in `assign_attributes' | |
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/associations/association.rb:236:in `block in build_record' | |
from /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/base.rb:500:in `initialize' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+-----------------+--------------+------+-----+---------+----------------+ | |
| Field | Type | Null | Key | Default | Extra | | |
+-----------------+--------------+------+-----+---------+----------------+ | |
| id | int(11) | NO | PRI | NULL | auto_increment | | |
| ProductName | varchar(255) | YES | | NULL | | | |
| ProductPrice | float | YES | | NULL | | | |
| ProductQuantity | int(11) | YES | | NULL | | | |
| ProductSupplier | int(11) | YES | | NULL | | | |
| created_at | datetime | NO | | NULL | | | |
| updated_at | datetime | NO | | NULL | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@font-face { | |
font-family: 'harbara'; | |
src: url('icomoon.eot'); | |
src: url('icomoon.ttf') format('truetype'); | |
font-weight: normal; | |
font-style: normal; | |
} |
NewerOlder