jatwell93 / rubyproject

1 stars 1 forks source link

workouts - model / controller - unnecessary relationships? #57

Open Mirv opened 7 years ago

Mirv commented 7 years ago

Hey - so I see zets is probably sets. Good, but any of those fields which are just numbers are probably better handled as an extra entry in the join table. Like on the recipe model, where we made feeds from a has_many into just a field on recipe's model(database table).

I feel like if zets is sets, that it and reps could probably just be made fields in the same way we took out the recipe controller. Then use a {Model}.where('{Condition is}', {some var}) to pull all workouts that are low repetitions.

That would look something like Workouts.where('reps <', 5) & would turn an activerecord hash of id's that were less than 5 reps...I haven't looked up the .where today on the rails api documentation, but that's close to what happens.

jatwell93 commented 7 years ago

I was thinking that might be what has to happen with that. Yeh zets was my way around the naming error haha. Is this a change that boosts performance?

Mirv commented 7 years ago

I don't think so, I queued in on it only after examining it - there's a normal method around this too.

This method is specifically for the usecase we have here....we want a specific name for a relationship but it's forbidden...

class AdminUser < ActiveRecord::Base
  has_many :articles, as: :owner
end

https://stackoverflow.com/questions/21246851/how-to-create-an-alias-name-for-a-model-in-rails-active-records