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 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
  • 3 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

Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
Hi I have a post model that :has_many :reply, when using searchlogic, doing Post.reply_content_like(search),
For example, I have a model Posts and Comments. Post.objects.annotate(Count('comment')) I am making such
So for example ... Lets say I have a Posts model and a News
Assuming I have a comments model and a posts model, What code can I
So I have a User model that :has_many other models like Documents, Videos, Posts
I have a Category and a Post model, with each Post belonging to a
I have a User model, a Post model, and an Interest model. User has_many
I have a typical, Post model: class Post< ActiveRecord::Base validates_presence_of :user_id #Line 1 validates_presence_of
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):

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.