| 93 | | There are two important points to notice here. First, the name of the table: by default Elixir, takes the name of the module followed by the name of your class lower cased. You can change that by [wiki:TutorialDivingIn#a7.Usingoptions using options], as we'll see later on. The other point is that Elixir generated an `id` column and used it as the primary key for our Entity. This is because we didn't provide a primary key ourselves. If you want to specify the primary key yourself, no problem just pass `primary_key=True` to the field(s) you want to act as the primary key. |
| 94 | | |
| 95 | | Now, we'll instantiate a first movie-object. You could add more movies here, but so far "Blade Runner" does the job. |
| | 93 | There are two important points to notice here. First, the name of the table: By default Elixir, takes the name of the module followed by the name of your class lower cased. You can change that by [wiki:TutorialDivingIn#a7.Usingoptions using options], as we'll see later on. The other point is that Elixir generated an `id` column and used it as the primary key for our Entity. This is because we didn't provide a primary key ourselves. If you want to specify the primary key yourself, no problem just pass `primary_key=True` to the field(s) you want to act as the primary key. |
| | 94 | |
| | 95 | Now, we'll instantiate our first movie-object. You could add more movies here, but so far "Blade Runner" does the job. |
| 284 | | Now, we think it would make a nice addition to our little application to relate movies to their genres. As most movie fall into several genres and that (hopefully) several movies belong to the same genre, we'll model that with a ManyToMany relationship. |
| 285 | | |
| 286 | | We would also like to not use the default surrogate 'id' primary key that we've had in the Movie entity so far. We could like to accept two movies with the same `title` but not on the same `year`. So a composite primary key on `title` and `year` seems like a good idea. |
| | 284 | Now, we think it would make a nice addition to our little application to relate movies to their genres. As most movies fall into several genres and (hopefully) several movies belong to the same genre, we'll model that with a ManyToMany relationship. |
| | 285 | |
| | 286 | We would also like to not use the default surrogate 'id' primary key that we've had in the Movie entity so far. We would like to accept two movies with the same `title` but not on the same `year`. So a composite primary key on `title` and `year` seems like a good idea. |
| 372 | | Elixir provides a default global contextual (thread-local) session for you to use, and Elixir entities are by default linked to that session by using that session's contextual mapper. It just means that whenever you create an instance of any of your entities, that instance is automatically added (save'd) to the session. If you want to use another session (for example, to not use a global/contextual session at all), that's fine, you just need to tell Elixir by using the corresponding option. |
| | 372 | Elixir provides a default global contextual (thread-local) session for you to use, and Elixir entities are by default linked to that session by using that session's contextual mapper. It just means that whenever you create an instance of any of your entities, that instance is automatically added (saved) to the session. If you want to use another session (for example, to not use a global/contextual session at all), that's fine, you just need to tell Elixir by using the corresponding option. |
| 413 | | Several points are important to notice. First, we used multi-table inheritance. Which means that each of these entities will get a table for themselves (with foreign keys to link them). For an explanation of the different kind of inheritance you can do, and what that involves, please refer once again to the [http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_inheritance corresponding SQLAlchemy documentation]. Note that Elixir currently only supports "single table" and "joined/multi-table" inheritance (both in their polymorphic and non polymorphic versions). Elixir generate the correct tables and mappers for you but it's still important for you to realize what that is. |
| 414 | | |
| 415 | | Secondly, when using inheritance with Elixir (and not using the default values), you have to tell Elixir what kind of inheritance you want in each and every entity, including the parent one. This is because some work needs to be done on the parent too for the inheritance to work and that entity needs to know that this extra processing needs to be done. |
| | 413 | Several points are important to notice. First, we used multi-table inheritance. Which means that each of these entities will get a table for themselves (with foreign keys to link them). For an explanation of the different kind of inheritance you can do, and what that involves, please refer once again to the [http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_inheritance corresponding SQLAlchemy documentation]. Note that Elixir currently only supports "single table" and "joined/multi-table" inheritance (both in their polymorphic and non polymorphic versions). Elixir generates the correct tables and mappers for you but it's still important for you to realize what that is. |
| | 414 | |
| | 415 | Secondly, when using inheritance with Elixir (and not using the default values), you have to tell Elixir what kind of inheritance you want in each and every entity, including the parent one. This is because some work also needs to be done on the parent for the inheritance to work and that entity needs to know that this extra processing needs to be done. |
| 461 | | By now, you should know how to create simple models and set up relationships between them. The next steps would be to first play a bit more with the model we've created. In case you lost it, or didn't follow the whole tutorial, you can use the [attachment:model.py complete model], as well as an [attachment:alltogether.py aggregated data set] you can play with. Then we suggest you to explore further the possibilities of Elixir by looking at our [http://elixir.ematia.de/apidocs/elixir.html API-docs] which is quite thorough and the [source:/elixir/trunk/tests/ testcases] which provide some nice examples. Also, the more experienced (or adventurous) programmers will probably be interested in what happens [wiki:BehindTheScene behind the scene]. |
| 462 | | |
| 463 | | And also, please remember than once the setup phase is done. Working with Elixir is just as working with plain SQLAlchemy (with a few shortcuts syntaxes provided for convenience), so reading the [http://www.sqlalchemy.org/docs/ SQLAlchemy documentation] is always a good idea. |
| | 461 | By now, you should know how to create simple models and set up relationships between them. The next step would be to play a bit more with the model we've created. In case you lost it, or didn't follow the whole tutorial, you can use the [attachment:model.py complete model], as well as an [attachment:alltogether.py aggregated data set] you can play with. Then we suggest you to explore further the possibilities of Elixir by looking at our rather thorough [http://elixir.ematia.de/apidocs/elixir.html API-docs] and the [source:/elixir/trunk/tests/ testcases] which provide some nice examples. Additionaly, the more experienced (or adventurous) programmers will probably be interested in what happens [wiki:BehindTheScene behind the scene]. |
| | 462 | |
| | 463 | Furthermore, please remember than once the setup phase is done. Working with Elixir is just as working with plain SQLAlchemy (with a few shortcuts syntaxes provided for convenience), so reading the [http://www.sqlalchemy.org/docs/ SQLAlchemy documentation] is always a good idea. |