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

  • Home
  • SEARCH
  • 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 5979415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:39:21+00:00 2026-05-22T21:39:21+00:00

I have a Posts model and every post also contains Blocks (also a model).

  • 0

I have a Posts model and every post also contains Blocks (also a model). I’m using the play framework for this website, and what I want to do is show X number of post with all of it’s blocks on one page. JPA (or play framework’s implementation, don’t know which one it is) has the find() method with which I could query for posts in my controller, and than I would send the post list to my view like this:

render(postList);

What I wanted to know is what would be the best way to send the blocks for each post to the view. I could add a getBlocks() method to my Post model, which sends back a blocksList, and call it from the view, but this seems messy to me, and it would defeat the purpose of MVC since the blocks would be fetched from the view.. (or am I wrong about this?)

Does JPA or Play! offer some way of retrieving the blocks together with the posts?

This is what my Post model looks like right now, without getters and setters:@Entity

@Table(name="posts")
public class Post extends GenericModel{

    @Id
    @Column(name="post_id")
    private int id;

    @Column(name="post_situation")
    private String situation;

    @Column(name="post_date")
    private Date date;

    @Column(name="post_userid")
    private int userid;

    private List<Block> blockList;
    public List<Block> getBlocks() {
        List<Block> block = null;
        return blockList;
    }

}

How should I do this?

  • 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-22T21:39:21+00:00Added an answer on May 22, 2026 at 9:39 pm

    Just use the one-to-many keyword:

    @OneToMany
    private List<Block> blockList;
    

    However it’s not clear if you need the getBlocks method. If you are just getting the blocks from the database then you don’t need this method.

    Note: you probably want to read more on @OneToMany. You can for example add the option @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE}) such that when you persist or remove a Post from the database, the inner blockList does the same.

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

Sidebar

Related Questions

i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from
I have a blog app and i want to show each post in a
So I have a User model that :has_many other models like Documents, Videos, Posts
I have two models, Article and Post that both inherit from a base model
I have seen posts that show three ways to reset the DMV views: Reset
I have 2 tables: posts tags Tags table is structured like this: post_id tag
In a typical User - Post - Comment model in Rails, every user can
I was researching something and came across this blog post at buildstarted.com about model
I have a model that has counter_cache enabled for an association: class Post belongs_to
So, I have a search form in my website which posts Search.Value as a

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.