has_many through: Question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

has_many through: Question

John Sanderbeck
I am building a Lunch Ordering Module for my app and I have these models currently

Menu
  :menu_date
  :menu_type

Meal
  :name
  :mentree_id
  :available_daily

Mentree
  :name

Msides
  :name

Mdrink
  :name

Right now I am using a has_and_belongs_to_many on

meals_menus
mdrinks_menus
meals_msides

What I need to have is a Meal of the Day as part of the Menu and I am thinking I should use a has_many through:

But I can't think how to structure this correctly

My goal is to have the cafeteria be able to turn on and off meals and drinks on the menu based on availability, so when the class orders lunch they can only choose the available meals.
However I have a Lunch Calendar that I want to show the meal of the day.

Suggestions on the proper Rails structure?

John

Untitled picture1.png

Untitled picture2.png





--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/294dba9b-5383-4e1a-b02a-a105b93adedb%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: has_many through: Question

Walther Diechmann
Hi John,

you might consider doing it this way:

calendars has_many events has_and_belongs_to_many menus has_and_belongs_to_many categories 

Calendar: name
Event: description + when_ical*
Menu: name + description + photos** + ancestry***
Category: name

* ical format 
** a Rails attachments construct
*** Rails gem affording tree-like structures

cheers
Walther

Den 4. aug. 2019 kl. 15.29 skrev John Sanderbeck <[hidden email]>:

I am building a Lunch Ordering Module for my app and I have these models currently

Menu
  :menu_date
  :menu_type

Meal
  :name
  :mentree_id
  :available_daily

Mentree
  :name

Msides
  :name

Mdrink
  :name

Right now I am using a has_and_belongs_to_many on

meals_menus
mdrinks_menus
meals_msides

What I need to have is a Meal of the Day as part of the Menu and I am thinking I should use a has_many through:

But I can't think how to structure this correctly

My goal is to have the cafeteria be able to turn on and off meals and drinks on the menu based on availability, so when the class orders lunch they can only choose the available meals.
However I have a Lunch Calendar that I want to show the meal of the day.

Suggestions on the proper Rails structure?

John

<Untitled picture1.png>

<Untitled picture2.png>





--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/294dba9b-5383-4e1a-b02a-a105b93adedb%40googlegroups.com.
ALCO Company Stop spam service.

Denne besked er blevet skannet af ALCO Stopspam, og menes at være fri for vira og spam. mener du at det er en spam mail er du velkomme til at trykker pålinket herunder. Det vil åbne et internet side og når den er færdig med at loade, kan den bare lukkes igen. Vores scanner vil derefter tage ved lærer og blive bedre til at spære for spam.  Mvh ALCO Company


Klik her for at rapportere denne besked som spam. 
<Untitled picture1.png>
<Untitled picture2.png>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0FEE0D03-6FE3-4205-A857-FC1D2ACF56A2%40diechmann.net.
Reply | Threaded
Open this post in threaded view
|

Re: has_many through: Question

John Sanderbeck
In reply to this post by John Sanderbeck
I think I got it...   I knew it had to be simple in Rails to do that...

Just had to add 

  belongs_to :motd, class_name: 'Meal', foreign_key: :motd_id

  has_and_belongs_to_many :meals
  has_and_belongs_to_many :mdrinks

Now I have a Meal of the Day as well as Daily Meals

John

On Sunday, August 4, 2019 at 9:29:08 AM UTC-4, John Sanderbeck wrote:
I am building a Lunch Ordering Module for my app and I have these models currently

Menu
  :menu_date
  :menu_type

Meal
  :name
  :mentree_id
  :available_daily

Mentree
  :name

Msides
  :name

Mdrink
  :name

Right now I am using a has_and_belongs_to_many on

meals_menus
mdrinks_menus
meals_msides

What I need to have is a Meal of the Day as part of the Menu and I am thinking I should use a has_many through:

But I can't think how to structure this correctly

My goal is to have the cafeteria be able to turn on and off meals and drinks on the menu based on availability, so when the class orders lunch they can only choose the available meals.
However I have a Lunch Calendar that I want to show the meal of the day.

Suggestions on the proper Rails structure?

John

Untitled picture1.png

Untitled picture2.png





--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ff41eba9-5ad5-41c9-b82f-d6f219f27acf%40googlegroups.com.