Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2

[eluser]Maglok[/eluser]
Greetings,

I am not sure if this should be possible, but I am noticing I am building around datamapper to get this to work.

I have no idea what it is called but: Lets say you have a relation with a class that can be one of many classes. Example: You got a Bowl with a relationship 'contents' and the contents can be all kinds of objects, Apple, Chocolate, Bananas, etc.

I feel it is close to datamapper, but that the database itself is not really playing nice with the concept. Am considering a huge jointable so I at least only need one table, but is there any tricks to get something like that to work in Datamapper without custom functions?

[eluser]WanWizard[/eluser]
No, this is not possible.

Datamapper (most ORM's do) has a fixed one-to-one object mapping in it's relations. This would require a combination of a FK and an object name in the parent table, which would then be used to determine which relation to access. It would also mean querying all these relations, and unifying the result of the query, which can get tricky if these different objects have different properties.

So, it would involve a new type of relation, that defines all underlying models (instead of just one), extension to the get() methods to query them all instead of just one, and new hydration logic to translate the results back to the object.

[eluser]Maglok[/eluser]
That's what I thought, but it never hurts to ask.

I can get around it regardless. I can see the Bowl example to be a perfectly workable design decision thus I wondered.

Regardless thank you very much for Datamapper still, it has found its way into every new project. Smile

[eluser]coldscooter[/eluser]
Am I able to define my own name for a joining field instead of joinTableName_id?

I want to be able to name a field 'image' that points to the id of a 'files' table.

[eluser]WanWizard[/eluser]
No, all foreign keys are required to have the suffix '_id'.

It's hardcoded, and very complex to change (which is why it hasn't happened yet).

[eluser]Maglok[/eluser]
But it might in 2.0!... Right? Smile

[eluser]WanWizard[/eluser]
It's at the top of the todo list, yes.

[eluser]Crackz0r[/eluser]
Humm i´m new at Datamapper ORM, and im just reading all the documentation and trying some snnipets... But now this come to my mind.... If your are no longer mantaining HTML Form, how should i generate forms based on the models... i dont get it very well.

Thank you in advanced

[eluser]WanWizard[/eluser]
Easy answer is: like you would make a form otherwise.

Having said that, there's nothing wrong with the form extension, it works fine, check the included example application.

[eluser]Crackz0r[/eluser]
OK. Thank you for your answer....

Humm but the extension will work for any future release of DMO?




Theme © iAndrew 2016 - Forum software by © MyBB