Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:17:03+00:00 2026-05-28T17:17:03+00:00

I have a question about handling my models. I get all confused. When I

  • 0

I have a question about handling my models. I get all confused. When I load the page I get a JSON string from rails containing “events” these events have in turn one user, multiple participants, multiple payments and multiple comments, these comments, have in turn one user, and the payments have multiple users and a single user. The comments and payments also have an event pointing back att the parent.

Events
  User
  Participants(users)
  Payments
    User
    Users
    Event
  Comments
    User
    Event

Okey, so the question is: Should I load everything as a tree, with full attributes everywhere:

"events": {
  "id": "event_1",
  "user": {
    "id": "user_1", "name":"name"
  }, "participants": [
    {"id": "user_1", "name":"name"},
    {"id": "user_2", "name":"name"}
  ], "payments": [{
      "id":"payment_1",
      "user": {
        "id": "user_1", "name":"name"
      },"users": [
        {"id": "user_1", "name":"name"},
        {"id": "user_2", "name":"name"}
      ], "event": {root event object}  
    }], "comments": [{
      "id": "comment_1",
      "user": {
        "id": "user_1", "name":"name"
      }, "event": {root event object}  
    }]
  }
}

And then have the events model, to create new comments, payments and users, and assign it to it’s own event, or is it a better idea to load every event, user payment and comment into separate variables, and then use the variable to get the models.
It is quite hard to explain, so feel free to ask if I need to clarify something.

Conclusion: Should I let the event model handle the creation of all the nested objects, or is there some better way to handle this, and have access to the models more globaly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:17:05+00:00Added an answer on May 28, 2026 at 5:17 pm

    Architecture is subjective, but here is how I would go about it –

    3 base models

    User = Backbone.Model.extend({
        defaults : {
            name : ""
        }
    })
    Payment = Backbone.Model.extend({
        defaults : {
            user : new User(),
            users : new UserList(),
            event : ""
        }
    })
    Comment = Backbone.Model.extend({
        defaults : {
            user : new User(),
            event : ""
        }
    })
    

    3 Collections

    UserList = Backbone.Collection.extend({
        model : User
    })
    PaymentList = Backbone.Collection.extend({
        model : Payment
    })
    CommentList = Backbone.Collection.extend({
        model : Comment
    })
    

    One Event model

    Event = Backbone.Model.extend({
        defaults : {
            user : new User(),
            participants : new UserList(),
            payments : new PaymentList(),
            comments : new CommentList()
        }
    })
    

    If you initialize your event object with the JSON in the above example, it should just work. In the future if you want to separate out your users to a different API, this code should support that too. If you do want to make the component objects available globally later on, you can just get it from the user object, i.e., window.User = myEvent.get(“user”)

    Hope this helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about using streams in .NET to load files from disk.
I'm new to Rails development and I have a question about handling an unknown
I have a question about Symbian active objects handling. What's the problem: my program
Just started with Android, and I have a question about handling images. I'm thinking
I have a question about handling exception. I have a Winform that uses a
I have a question about event handling with C#. I listen to events a
I have a question about inner-workings of Python sub-interpreter initialization (from Python/C API) and
I have a question about form handling with OO programming, The way I am
I have a question about error/exception handling on the iPhone. I've read the documentation
I have a question about exception handling. To prevent the [YourProgram] has stopped working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.