Last active
December 10, 2015 02:19
-
-
Save tubbo/4367206 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Appointment < ActiveRecord::Base | |
| attr_accessible :booking_resource_id, :boooking_id, :customer_id | |
| belongs_to :customer | |
| belongs_to :booking | |
| end |
This file contains hidden or 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 Booking < ActiveRecord::Base | |
| has_many :booking_resources | |
| has_one :appointment | |
| has_one :customer, :through => :appointment | |
| attr_accessible :approved, :approvedBy, :note, :end, :start, :title, :customer_id, :booking_resource_id | |
| validates :start, :end, :overlap => {:scope => "booking_resource_id"} | |
| def start_cannot_be_future | |
| if self.start > self.end | |
| errors.add(:start, "Date can't be in the future") | |
| end | |
| end | |
| end |
This file contains hidden or 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 BookingResource < ActiveRecord::Base | |
| attr_accessible :name, :color | |
| belongs_to :booking | |
| validates :name, :uniqueness => true | |
| end |
This file contains hidden or 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 Customer < ActiveRecord::Base | |
| attr_accessible :address, :city, :company, :fname, :lname, :state, :zip | |
| has_many :bookings, :through => :appointments | |
| end |
This file contains hidden or 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
| 1.9.3-p194 :009 > BookingAppointment | |
| => BookingAppointment(id: integer, customer_id: string, booking_id: string, booking_resource_id: string, created_at: datetime, updated_at: datetime) | |
| 1.9.3-p194 :003 > @booking = Booking.find(2) | |
| Booking Load (0.3ms) SELECT "bookings".* FROM "bookings" WHERE "bookings"."id" = ? LIMIT 1 [["id", 2]] | |
| => #<Booking id: 2, start: "2012-12-10 00:00:00", end: "2012-12-18 00:00:00", approved: false, approvedBy: "", customer_id: 1, booking_resource_id: 2, created_at: "2012-12 | |
| -10 01:22:40", updated_at: "2012-12-16 07:07:31", title: "asdf", ipads: nil, note: nil> | |
| 1.9.3-p194 :004 > @app = BookingAppointment.find(1) | |
| BookingAppointment Load (0.2ms) SELECT "booking_appointments".* FROM "booking_appointments" WHERE "booking_appointments"."id" = ? LIMIT 1 [["id", 1]] | |
| => #<BookingAppointment id: 1, customer_id: "1", booking_id: "2", booking_resource_id: "2", created_at: "2012-12-24 01:27:23", updated_at: "2012-12-24 01:58:30"> | |
| 1.9.3-p194 :005 > @app.booking | |
| Booking Load (0.2ms) SELECT "bookings".* FROM "bookings" WHERE "bookings"."id" = 2 LIMIT 1 | |
| => #<Booking id: 2, start: "2012-12-10 00:00:00", end: "2012-12-18 00:00:00", approved: false, approvedBy: "", customer_id: 1, booking_resource_id: 2, created_at: "2012-12 | |
| -10 01:22:40", updated_at: "2012-12-16 07:07:31", title: "asdf", ipads: nil, note: nil> | |
| 1.9.3-p194 :006 > @app.customer | |
| Customer Load (0.2ms) SELECT "customers".* FROM "customers" WHERE "customers"."id" = 1 LIMIT 1 | |
| => #<Customer id: 1, company: "Big Inc", fname: "Joe", lname: "Shmoe", address: "123 cool st", city: "Orlando", state: "fl", zip: "32746", created_at: "2012-12-09 21:01:02 | |
| ", updated_at: "2012-12-09 21:01:02"> | |
| 1.9.3-p194 :007 > @app.booking_resource | |
| BookingResource Load (0.3ms) SELECT "booking_resources".* FROM "booking_resources" WHERE "booking_resources"."id" = 2 LIMIT 1 | |
| => #<BookingResource id: 2, name: "M2", created_at: "2012-12-16 07:05:24", updated_at: "2012-12-16 07:05:24", color: "green"> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment