• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Problem" with CodeIgniter and DataMapper (Databasedesign)

#1
[eluser]felix_[/eluser]
Hey,
i must use Datamapper instead of Doctrine in my actually project and im having some small problems with this.

Im using some simple relationships in my project.

For Example i build a small ticket system so that a user can create a ticket ... the admin can answer and the messages belong to the ticket.

I noticed that there is no way to auto create the tables.... so i did it in my personal way but this seems to be wrong with datamapper.

For Example: i would store the authors id of a message in the table Messages so i can resolve who wrote this text. And i would store the users is of the user who created the ticket in the Tickets table etc.

But this seems not to work.

Is it right that i hav to create a seperate table for each of this simple relationships?

It seems i hav to create tickets_users, tickets_messages, users_messages and so on

So is it correct to creat such a big amount if tables? normally i would create these tables only in n:n relationships and not 1:n

I also looked for a guid who tables hav to look like for datamapper but i didnt found anything

Hope someone can answer my question

greetz

#2
[eluser]NeoArc[/eluser]
I use a reference field:

object_type INT UNSIGNED (INDEX KEY??)

And then:

Code:
$ms = new Message();
$rows = $ms->where('object_type', Message::USER_MESSAGE)->get_iterated();

Code:
$m = new Message();
$row = $m->where('object_type', Message::USER_MESSAGE)->get_by_id($message_id);

#3
[eluser]WanWizard[/eluser]
The logic needed for autocreation of tables is something you drag along with every load of Datamapper. So for performance reasons I've choosen not to add this automatic mechanism.
I am thinking about some semi-automatic ways of doing this, but haven't found a good solution yet.

The naming rules of Datamapper are quite simple, and very well documented in the user guide:
- models are named singular, tables plural (model User, table users)
- every table MUST have a primary key called 'id', which MUST be an integer
- every foreign key MUST be named {model}_id

If you have one-to-many relations, you can work with in-table foreign keys (for example, a country has many users, users only one country. In this case you can add country_id to the users table). If you have a many-to-many relationship, you MUST create a relationship or junction table. This table MUST contain a primary key ('id'), and the foreign keys of both tables in the relationship. The junction table MUST be called {tableA}_{tableB}, in alphabetical order. For consistency reasons you can also use junction tables for one-to-many relationships, but it's not required.

I suggest you spend some time reading the user guide, in particular http://datamapper.wanwizard.eu/pages/relationtypes.html

#4
[eluser]felix_[/eluser]
[quote author="WanWizard" date="1305146591"]The logic needed for autocreation of tables is something you drag along with every load of Datamapper. So for performance reasons I've choosen not to add this automatic mechanism.
I am thinking about some semi-automatic ways of doing this, but haven't found a good solution yet.

The naming rules of Datamapper are quite simple, and very well documented in the user guide:
- models are named singular, tables plural (model User, table users)
- every table MUST have a primary key called 'id', which MUST be an integer
- every foreign key MUST be named {model}_id

If you have one-to-many relations, you can work with in-table foreign keys (for example, a country has many users, users only one country. In this case you can add country_id to the users table). If you have a many-to-many relationship, you MUST create a relationship or junction table. This table MUST contain a primary key ('id'), and the foreign keys of both tables in the relationship. The junction table MUST be called {tableA}_{tableB}, in alphabetical order. For consistency reasons you can also use junction tables for one-to-many relationships, but it's not required.

I suggest you spend some time reading the user guide, in particular http://datamapper.wanwizard.eu/pages/relationtypes.html[/quote]

thanks for your answer... i found my mistake
i did not name the columns exactly as needed

workin now Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.