database - Rails join tables or HABTM associations -


I am creating an application, in the application, I want to make events, then by registering directly for the event, creating a team By registering or joining an existing team, you can register for the event. I have originally set it up, as is the event- several teams, teammay user, user belongs_to team and event. However, if a registered user wants to join another event (or a team for another event), then I expect problems, and whenever I want to list things like @User.Event or @UserTemplates in Control Panel. Try to use someone to join these in a table and make a registration model / migration. Can I have a model that falls under the event, team and user? Am I doing all this wrong?

You can create a joined model registration, and relative_to polymorphic, so that it can be of any type Could reference the object. Here's an example:

Model / team.rb:

  The square team & lt; ActiveRecord :: Base has has_many: registration, as: = & gt; : Owner end  

model / user.rb

  class user & lt; ActiveRecord :: Base has has_many: registration, as: = & gt; : Owner end  

model / registration .bb

  class registration & lt; ActiveRecord :: Base is_to: owner ,: polymorphism = & gt; True end  

model / event.rb

  class event & lt; ActiveRecord :: Base has_many: Registration expired  

db / migration / 1234_add_registrations.rb

  ... t.belongs_to: owner ,: polymorphic = & gt; ; True t.belongs_to: Event ...  

Now you can check the registration to see who has signed up for your event. You can use has_many: Events, through =>: Registration ,: Source =>: For the users back to the owners, but note that there are some limitations, such as I: owners, through =>: Registration , Like plugins like


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -