[erlang-questions] Why is this delete_object giving me an error?
Jeroen Koops
koops.j@REDACTED
Mon Mar 16 17:12:25 CET 2009
On Mon, Mar 16, 2009 at 3:18 PM, ryeguy <ryeguy1@REDACTED> wrote:
> Oh, so is there no way to directly delete an object using a secondary
> index? ID would be my primary index, so I would have to either :
> A) Get the ID and delete by that with delete() or
> B) Get the whole record and delete by that with delete_object()?
>
> Do I understand this correctly?
You do - and typically, you would use delete_object only if your table is of
type bag - otherwise, you'd always use delete.
>
> On Mar 16, 9:21 am, Jeroen Koops <koop...@REDACTED> wrote:
> > Hi,
> >
> > dirty_delete_object (and also delete_object) can only be used with a
> > complete record - i.e. all fields must be filled in. It does not accept
> > wildcard patterns.
> >
> > If you want to delete all user with a certain first name, you need an
> index
> > on the first_name attribute, query for all users with that first name
> using
> > mnesia:index_read or dirty_index_read, and finally manually delete all
> > returned records with delete_object or delete.
> >
> > Regards,
> >
> > Jeroen
> >
> > On Mon, Mar 16, 2009 at 2:05 PM, ryeguy <ryeg...@REDACTED> wrote:
> > > I don't see what's wrong here, but I may just misunderstand the
> > > syntax. I'm trying to delete a "user" record from my "user" mnesia
> > > table who have the first name of "ryan" (there are multiples of them).
> > > Here is what I do:
> >
> > > Delete=#user{first_name = "ryan", _ = '_'},
> > > mnesia:dirty_delete_object(Delete)
> >
> > > Here is my record definition:
> > > -record(user, {id,
> > > username,
> > > password,
> > > email,
> > > first_name,
> > > last_name,
> > > last_login, % Date/time user last logged in
> > > reg_date}). % Date/time user registered the
> > > account
> >
> > > And here is the exception I'm getting:
> > > ** exception exit: {aborted,
> > > {bad_type,user,
> > > {user,'_','_','_','_',"ryan",'_','_','_'}}}
> > > in function mnesia:abort/1
> > > in call from users:register/1
> >
> > > It seems like a perfect match. What could cause this problem?
> >
> > > _______________________________________________
> > > erlang-questions mailing list
> > > erlang-questi...@REDACTED
> > >http://www.erlang.org/mailman/listinfo/erlang-questions
> >
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questi...@REDACTED://
> www.erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090316/0dc52142/attachment.htm>
More information about the erlang-questions
mailing list