Closed coalwater closed 1 month ago
So the purpose of that, is that every shift can be posted once for trade and the same shift can not be posted more than once.
So it copies the shift that the user wants to trade and post the shift for trade in PostedShifts/index. So it's just a copy of the shift object that the user needs to trade.
Do you have a better suggestion?
Copying data in the database is a hassle, you'll have to make sure of consistency and every thing, I think you should use the same post object with a state, like 'posted_for_trade' for example, but to make sure that a single shift can not be traded more than once you could set up a workflow, this way you can make sure that states can move only in a single direction, like
not_for_trade -> posted_for_trade -> traded
and another flow could be
not_for_trade -> posted_for_trade -> cancelled
and prevent the flow to go in the <-
direction, there's a lot of gems that handle that for you, check this one for example, this way you can know for sure that a single shift can't be traded more than once
Thats actually great I been reading and watching some tutorial about state machines wow. But here you said to use the post object. Did you mean the Shift Object? If its the Shift object that I should use there will be a slight issue. For each shift I should be able to post each shift for trade but I can also sell part of my shift instead of the whole shift. And wouldnt that directly modify time of the shift object that the user have?
For instance, If I work on the 28 feb 2015 from 0900 - 1700, I should be able to sell a part of it, if I want. For example, I could sell 1400 - 1700 or 0900-1400. The only thing is that the shift cant be split more than once. That means If i sold 1400-1700 I am left with 0900-1400 , I can not split the part that I am left with. But I can completely sell the whole 0900-1400 but not split it.
So the issue is that if I decided to post for trade 1400-1700 that would change the time of the shift object to 1400-1700 correct?
yes i did mean shift object, and for the problem i don't know what would be the best solution, we could let the system split the shift into two, but that would be kind of a hassle, what do you think would be better?
I'm thinking copying the object but you said its to much of an hassle. So maybe adding extra time attributes to the shift object. So for example, start_time_for_trade and finish_time_for_trade. And when the object is in a posted_for_trade states. These column would be use for the trade. Once a trade has been made, modify the actual object's start and finish time .
I don't like the idea of copying, if there's things that's going to change a lot then we could split it in another table, and then a single shift would have many rows in the new table, but what I'm thinking of now is what exactly to split, and what to call it, and how to still keep the history intact, so i could at any point know which shifts were split and which were not, unless you don't need to do know that.
What i was thinking is for example having a shift that belongs to user, and shift_periods or shift_times table that belong to shift, a single shift might have many of those records, and maybe only the last one of the may is the final state of the shift, but what i can't figure out yet is how to know who is the other person who took the other half of the shift.
Hey I haven't been active because of mid-terms, but I was still thinking about your suggestion, and I decided to work on an ERDto help me see better what I'm actually aiming for here is what I got for now(more to be added):
I also have another version that I have been working on to confirm my association. It works pretty well I am able to see what language does the user can speak, what position the user can do. As for shifts, I remember you said that you would rather not copy data but I want to keep track of how many trades a user has done as well. If the user splits the shift I cant be using the same shift model to keep track of the trade. There's is problem that I have, I would like to be able to say for instance 'user.qualifications' and be able to display all the language and position the user has(but that's minor details for later). I am missing the pivot table between position and user but it would be similar to user and language table. Here's what each model look like(if you need me to put it on git let me know):
class Language < ActiveRecord::Base
has_many :users, :through => :speaks
has_many :speaks
end
class Speak < ActiveRecord::Base
belongs_to :language
belongs_to :user
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :languages, :through => :speaks, :foreign_key => "language_id"
has_many :speaks, :foreign_key => "user_id"
has_many :positions
has_many :qualifications
has_many :shifts, :foreign_key => "current_owner"
has_many :tradeshifts
end
In your code you have a
:shift
thathas_one :posted shift
, what's the difference between the two?