Hi Damien,
your approach is certainly very interesting. Congratulations, you are
the first one to use Magritte together with a relational database!
I was thinking about similar things, especially using Magritte (maybe
together with ROE) to do relational object mapping. Having a generic
framework like this would be very cool.
Basically Magritte descriptions can be directly mapped to a
relational-database:
- MAConatiner --> Table (that automatically alter the tables as soon
as the containing descriptions change)
- MAElementDescription --> Column
- MAStringDescription -> VARCHAR
- MANumberDescription -> INT
- MADateDescription -> DATE
- ...
- MAeRelationship --> Foreign Key
- MAOneToOneRelationship -> 1:1 mapping
- MAOneToManyRelationship -> 1:n mapping
You are using the MAAssociationDescription to do the mapping from the
db-id to the object? I think a database-layer should be as
transparent as possible and not require the programmer to think about
ids and primary-keys, etc. But yeah, this is not an easy problem ;-)
I am interested to see a demo of your code!
Lukas
On 9 Nov 2005, at 08:00, Damien Cassou wrote:
Hi Lukas,
I found a problem and a solution what do you think about it ?
My project works with DB. I have a Table State which stores
different stats (Switzerland, France, Espana...). I have a table
Person with a field for the orign state (where the person was borned).
When I edit a person, I want a SingleOptionComponent representing
the different states in the DB (the state names). And when I save
the form, I want the Id of the state, not its name (because the
Person table use a foreing key to the state table).
My Solution :
- Add a new field for MADescription named : #withId (and implement
isWithId, beWithId...)
- Create an AssociationDescription with a #kind method returning
the class Association. AssociationDescription inherit from
MAElementDescription.
- Add a description to the person with:
options: (MADynamicObject on: [GISQL
getNamesCollectionFrom: 'Select Id, Name FROM State ORDER BY Name']);
reference: GIAssociationDescription new;
#getNamesCollectionFrom returns an association collection of type
Id->Name
When I want to get the Id of the model with the description I use :
value := description accessor read: aDescribedObject.
description isWithId ifTrue: [ value := value key ].
It works great. What is your opinion about this ?
Thanks
--
Lukas Renggli
http://www.lukas-renggli.ch