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

[eluser]WanWizard[/eluser]
Datamapper doesn't work on reactor.

The core is constantly being changed, I don't have the time and patience to make it work every time it breaks (and when I make it work it breaks for people not using an up to date reactor version).

Once there's a new release out, I'll start again. For now, up to CI 2.1.0 only.

You can try modifying the third party DB file, but you'll probably get stuck on other core changes, like making the internals of the DB classes protected. DM relies on full class access, the current bootloader is a clumsy workaround for that.

With a closed down core, the only possible action towards CI 3 is a rewrite of Datamapper. Which I won't look at as long as there is no CI 3.

[eluser]weboap[/eluser]
Thanks for the advice. and for the excellent job with Dattamapper.

[eluser]Victorelu[/eluser]
Hi there! I have been playing around with Datamapper ORM for a few weeks now and I have stumbled upon an issue which I was hoping I could get some help with as my Googling skills have disappointed me.

I have two tables: Products and Sizes, with a many to many relationship between them which definitely works (insert/select tested). The join table is as follows:
products_sizes with the following columns: id, product_id, size_id, price.

What I would like to do is to remove one join row from the table by querying one of the join_field - in particular "id". I am not sure if it's the best practice and I could workaround the issue by deleting the row based on the product id and size id but I was hoping this was possible.

Thank you for your time and the great development+manual! Smile

[eluser]WanWizard[/eluser]
What usually works best for me if I have additional fields in the relationship table, or I need to access the table directly, is break up the many-to-many into two many-to-one's.

To do so, create a model for your relationship table (lets call it Productsizes), and define a has_many from Products to Productsizes, a has_many from Sizes to Productsizes, and a has_one from Productsizes to Products and Sizes.

Now you can just query the table like any other.

If needed you can still maintain the many-to-many relation at the same time, to have easy access from Products to Sizes (or the other way around).

[eluser]Victorelu[/eluser]
Thank you for the reply and the idea! It seems to bring a little bit more complexity to the system but I believe I need this complexity.

Just a quick question regarding maintaining the many-to-many relationship table - would it be the same table as Productsizes? If so, doesn't it *have* to be named Products_sizes?

Thanks again!

Edit: It seems that it worked. Thanks for the help!

[eluser]WanWizard[/eluser]
You just keep the existing has_many definition that links Products to Sizes (and automatically assumes the relation table is called 'products_sizes.).

Besides that you create a model called 'Productsizes', add a class property "$table = 'products_sizes"' to force the model to use that table, and define the relations as described.

You can then do:
Code:
$p = new Product(1);

// get this products sizes, use the existing many-to-many
$p->sizes->get();

// get the prices of products > 100, including size info, use the intermediate model
$p->productsize->include_related_sizes()->where('price >', 100)->get();

[eluser]Hakkai[/eluser]
is there any other way for me to repopulate the form after the validation failed?

[eluser]WanWizard[/eluser]
Don't ask the same questions in two different threads please.

[eluser]coldscooter[/eluser]
Is there a way to use a regular expression in the validation rules of DataMapper? So if i wanted to validate the format of a telephone number or postal code.

[eluser]WanWizard[/eluser]
Not in the rule definition, you'll have to make a validation method for that.




Theme © iAndrew 2016 - Forum software by © MyBB