Am Dienstag, 13. November 2012 01:01:11 UTC+1 schrieb James Roper:
> Sorry, I was in the wrong forum, thought this was the Play forum :(
> I need to find that on switch for my brain...
> On Tuesday, 13 November 2012 11:00:15 UTC+11, James Roper wrote:
>> Well, ebean should do the cascading deletes for you manually, that's why
>> it doesn't generate the ddl. But, the ddl generation is just a temporary
>> thing for helping you get started quickly in a project. Once it no longer
>> satisfies your needs, you should maintain it manually, at that point Play
>> won't generate it for you anymore.
>> On Tuesday, 13 November 2012 05:19:51 UTC+11, Stefan wrote:
>>> Hello all,
>>> I am modelling the following:
>>> One NewsArticle has multiple Comments, each Comment belongs to exactly
>>> one NewsArticle.
>>> In SQL formulation: There is a foreign key from the Comment table to the
>>> primary key in the NewsArticle table.
>>> I successfully modelled this using Ebean (please see code below), but I
>>> am yet missing one thing: When a NewsArticle is deleted, all associated
>>> Comments shall be deleted. In SQL this would be "on delete cascade". How do
>>> I get Ebean to generate "on delete cascade" in DDL? (jdbc mysql). Currently
>>> Ebean generates "on delete restrict" instead of the intended "on delete
>>> cascade".
>>> My code as of now is:
>>> *NewsArticle:*
>>>> @Entity
>>>> public class NewsArticle extends Model {
>>>> @Id
>>>> public Integer news_id;
>>>> @Column(nullable=false)
>>>> public String title;
>>>> @Column(nullable=false)
>>>> public String text;
>>>> @OneToMany(cascade=CascadeType.REMOVE)
>>>> @Column(nullable=false)
>>>> public List<Comment> comments;
>>>> }
>>> * Comment:*
>>>> @Entity
>>>> public class Comment extends Model {
>>>> @OneToOne(cascade=CascadeType.REMOVE)
>>>> @Column(nullable=false)
>>>> public NewsArticle news;
>>>> @Id
>>>> public Integer comment_id;
>>>> @Column(nullable=false)
>>>> public String text;
>>>> }
>>> This code generates the tables and the foreign key constraint for the
>>> Comments without any problem, but it generates "on delete restrict" instead
>>> of "on update cascade"? ): How to tell Ebean to generate "on delete
>>> cascade"?
>>> Thanks for any hint :-)