Accessing fields in many-to-many table |
[eluser]Unknown[/eluser]
Hello, I'm using Datamapper ORM v1.8, and I'm trying to access a field that is specific to the many-to-many relationship table, but I'm having difficulty as this isn't discussed in the documentation. If we use the example in the documentation where the models Author and Book are joined by the authors_books table, where this table contains the fields id, author_id and book_id. Let's say that this table also includes a field called random_data. How would the value of random_data be accessed from the author object? The following does not work Code: class Author extends DataMapper { If I tried selecting $this->authors_books->, I get an error regarding authors_books being a non-object. How should I proceed?
[eluser]WanWizard[/eluser]
You can't access join fields directly from the object, as join tables are 'invisible' from the relations point of view. Read the section in the manual about Join Fields.
[eluser]bEz[/eluser]
sample code should be updated as following correct? Code: // Create objects
|
Welcome Guest, Not a member yet? Register Sign In |