[erlang-questions] QLC Join Question for Mnesia

Pat McNally pat.mcnally@REDACTED
Sat Mar 1 18:22:59 CET 2008

I'm new to the world of Erlang and just starting to play around with Mnesia.

Lets say I have those two records. I want to compose a query that will
pull a basket out of the database and fill it with a list of all the
apples that have their basket_id set to the same id as the basket.

-record(basket, {id, apples = []}).
-record(apple, {id, brand, basket_id}).

I can do something like this:
(where Id is the id of the basket I'm looking for)

qlc:q([B#basket{apples = A} || B <- mnesia:table(basket),
					    B#basket.id =:= Id,
					    A <- mnesia:table(apple),
					    A#apple.basket_id =:= B#basket.id]).
However when I run that query it only returns a single apple in the
basket, as opposed to a list of apples.

Is it possible to do this in a single query?

More information about the erlang-questions mailing list