Saving a related model in constructor

35 views
Skip to first unread message

Subbu

unread,
Dec 30, 2011, 1:33:22 AM12/30/11
to play-fr...@googlegroups.com
How can I save a related model within a constructor. For example:

public class Magazine extends Model {
  public Magazine() {
    new Subscription(this, user); // automatically make the owner subscribe to the magazine
  }
}

public class Subscription extends Model {
  public Subscription(Magazine magazine, User user) {
    this.magazine = magazine;
    this.user = user;
  }
}

Magazine m = new Magazine();
======

When I create a new Magazine object and save it, it doesn't save the Subscription model. Is there anything I am doing wrong here?

Pascal Voitot Dev

unread,
Dec 30, 2011, 5:45:18 AM12/30/11
to play-fr...@googlegroups.com
First impression:
You're not saving the subscription when you save the magazine (or there is a cascade I don't know)

Pascal

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/toIvFOde7UMJ.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.

Subbu

unread,
Dec 30, 2011, 7:04:03 AM12/30/11
to play-fr...@googlegroups.com
When I save the parent model i.e Magazine, does the child get saved too?

Subbu

unread,
Dec 30, 2011, 7:06:03 AM12/30/11
to play-fr...@googlegroups.com
Sorry, I meant: When I save the parent model i.e Magazine, shouldn't the child get saved too?

Pascal Voitot Dev

unread,
Dec 30, 2011, 7:24:57 AM12/30/11
to play-fr...@googlegroups.com
AFAIK, it depends on how you wrote your model, of the cascade type...

On Fri, Dec 30, 2011 at 1:06 PM, Subbu <subramani...@gmail.com> wrote:
Sorry, I meant: When I save the parent model i.e Magazine, shouldn't the child get saved too?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To view this discussion on the web visit https://groups.google.com/d/msg/play-framework/-/-uLsUKQa_mAJ.
Reply all
Reply to author
Forward
0 new messages